Dart 日期时间 DateTime
1、获取当前时间
var now = new DateTime.now();
print(now); // 2019-06-20 16:59:05.560543
2、设置时间
var d =new DateTime(2019, 6, 20, 16, 37 , 26);
print(d); // 2019-06-20 16:37:26.000
3、创建时间UTC
var ds = new DateTime.utc(2019, 10, 10, 9, 30);
print(ds); // 2019-10-10 09:30:00.000Z
4、解析时间
var d1 = DateTime.parse('2018-10-10 09:30:36');
print(d1); // 2018-10-10 09:30:36.000
var d2 = DateTime.parse('2018-10-10 09:30:30+0800');
print(d2); // 2018-10-10 01:30:30.000Z
5、时间加减
print(now.add(new Duration(minutes: 10)));//加10分钟 2019-06-20 17:09:05.560543
print(now.add(new Duration(minutes: -10)));//减10分钟 2019-06-20 16:49:05.560543 print(now.add(new Duration(hours: 2)));//加2小时 2019-06-20 18:59:05.560543
print(now.add(new Duration(hours: -2)));//减2小时 2019-06-20 14:59:05.560543
6、比较时间
var d3 = new DateTime(2019, 6, 20);
var d4 = new DateTime(2019, 7, 20);
var d5 = new DateTime(2019, 6, 20); print(d3.isAfter(d4));//是否在d4之后 false
print(d3.isBefore(d4));//是否在d4之前 true
print(d3.isAtSameMomentAs(d5));//是否相同 true
7、计算时间差
var d6 = new DateTime(2019, 6, 19, 16 , 30);
var d7 = new DateTime(2019, 6, 20, 15, 20);
var difference = d7.difference(d6);
print([difference.inDays, difference.inHours,difference.inMinutes]);//d6与d7相差的天数与小时,分钟 [0, 22, 1370]
8、时间戳
print(now.millisecondsSinceEpoch);//单位毫秒,13位时间戳 1561021145560
print(now.microsecondsSinceEpoch);//单位微秒,16位时间戳 1561021145560543
9、打印当前时间
// padLeft(int width,String sring):如果字符串长度小于width,在左边填充sring
print("${now.year.toString()}-${now.month.toString().padLeft(2,'0')}-${now.day.toString().padLeft(2,'0')} ${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}:${now.second.toString().padLeft(2, '0')}");
// 2019-06-20 16:59:05
Dart 日期时间 DateTime的更多相关文章
- POCO库——Foundation组件之日期时间DateTime
日期时间DateTime:内部提供多个设计计时器.日期.时区.时间戳等: Clock.h :Clock时钟计时类,_clock:Int64类型时钟值,CLOCKVAL_MIN.CLOCKVAL_MAX ...
- [ Python入门教程 ] Python中日期时间datetime模块使用实例
Python中datetime模块提供强大易用的日期处理功能,用于记录程序操作或修改时间.时间计算.日志时间显示等功能.datatime模块重新封装了time模块,提供的类包括date.time.da ...
- WP开发笔记——日期时间DateTime.Now函数
//2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString(& ...
- Python 日期时间datetime 加一天,减一天,加减一小时一分钟,加减一年
计算年.月.日需要安装组件包 pip install python-dateutil 当前日期时间 import datetime print datetime.datetime.now() # 20 ...
- ASP.NET C# 日期 时间 年 月 日 时 分 秒 格式及转换(转自happymagic的专栏)
在平时编码中,经常要把日期转换成各种各样的形式输出或保持,今天专门做了个测试,发现DateTime的ToString()方法居然有这么多的表现形式,和大家一起分享. DateTime time=Dat ...
- ASP.NET 日期 时间 年 月 日 时 分 秒 格式及转换
在平时编码中,经常要把日期转换成各种各样的形式输出或保持,今天专门做了个测试,发现DateTime的ToString()方法居然有这么多的表现形式,和大家一起分享. DateTime time=Dat ...
- C#中获取不同的日期时间格式
通过调用类中的各种方法我们可以获取不同的时间: 如:日期(2008-09-04).时间(12:12:12).日期+时间(2008-09-04 12:11:10)等. //获取日期+时间 DateTim ...
- 【转】Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历))
Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历)) 本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog. ...
- PL/SQL学习笔记之日期时间
一:PL/SQL时间相关类型 PL/SQL提供两个和日期时间相关的数据类型: 日期时间(Datetime)数据类型 时间间隔类型 二:日期时间类型 datetime数据类型有: DATE TIMEST ...
随机推荐
- WPF 的 Application.Current.Dispatcher 中,Dispatcher 属性一定不会为 null
原文:WPF 的 Application.Current.Dispatcher 中,Dispatcher 属性一定不会为 null 在 WPF 程序中,可能会存在 Application.Curren ...
- Flutter Image(图片)
Image是一个用于展示图片的组件.支持 JPEG.PNG.GIF.Animated GIF.WebP.Animated WebP.BMP 和 WBMP 等格式. Image 有许多的静态函数: ne ...
- 2019年北航OO第4单元(UML)总结
1 架构设计 经过了接近一学期的程序设计训练,在这一单元的第一次作业中我就非常注重架构的设计,竭力避免像之前一样陷入"第一次作业凑合,第二次作业重构"的不健康的迭代模式.整体上来说 ...
- Jmeter获取数据库数据
1)添加需要的数据库驱动jar包,使用不同的数据库,需要引入的jar包是不一样的: mysql:无需引入其他数据库驱动jar包 sql server:下载sqljdbc.jar包 oracle:ora ...
- js --策略模式
策略模式的定义: 将算法一个个的单独进行封装,并且使他们可以相互替换.此模式让算法的变化不会影响到使用算法的客户. 先回顾一下,我们在做项目的过程中,是不是经常会遇见因为业务逻辑的关系,我们会写好多的 ...
- js求对象数组的交集/并集/差集/去重
1.求交集 var arr1 = [{name:'name1',id:1},{name:'name2',id:2},{name:'name3',id:3}]; var arr1Id = [1,2,3] ...
- 安装CDH 5.15.1详解
安装CDH 5.15.1详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装Cloudera Manager 和CDH 1>.登陆Cloudera Manager ...
- DNS子域授权,区域传送
dig 命令 +recurse 递归查询 默认 +norecurse 不递归查询 dig +recurse -t A www.baidu.com @127.0.0.1 dig -t a ...
- 28.XSD(XML Schema Definition)用法实例介绍以及C#使用xsd文件验证XML格式
转自https://www.cnblogs.com/gdjlc/archive/2013/09/08/3308229.html XML Schema 语言也称作 XML Schema 定义(XML S ...
- markdown里面编辑代码
转:http://c.biancheng.net/view/6623.html ------------------------------------------------------------ ...