当前位置:网站首页>Dart-Flutter DateTime日期转换
Dart-Flutter DateTime日期转换
2022-08-02 03:27:00 【翊兮】
1.日期转换成时间戳
var now=new DateTime.now();
print(now.millisecondsSinceEpoch); //单位毫秒,13位时间戳
2.时间戳转换成日期
var now=new DateTime.now();
var a=now.millisecondsSinceEpoch; // 时间戳
print(DateTime.fromMillisecondsSinceEpoch(a));
3.创建指定时间
DateTime assignDay = new DateTime(2020,10,10);
print(assignDay); // 2020-10-10 00:00:00.000
4.计算时间跨度
// 例如计算1天14小时45分的跨度
Duration timeRemaining = new Duration(days:1, hours:14, minutes:45);
print(timeRemaining); // 38:45:00.000000
5.字符串转DateTime
DateTime.parse('2019-11-08') 或者 DateTime.parse('2019-11-08 12:30:05')
6.在之前——时间比较
var today = DateTime.now();
var date = DateTime.parse("2019-06-20 15:32:41");
today.isBefore(date);
7.在之后——时间比较
var today = DateTime.now();
var date = DateTime.parse("2019-06-20 15:32:41");
today.isAfter(date);
8.相等——时间比较
var today = DateTime.now();
var date = DateTime.parse("2019-06-20 15:32:41");
today.isAtSameMomentAs(date);
9.时间增加
var today = DateTime.now(); // 2019-11-08 02:54:53.218443
var fiftyDaysFromNow = today.add(new Duration(days: 5));
print('today加5天:$fiftyDaysFromNow'); // today加5天:2019-11-13 02:54:53.218443
10.时间减少
var today = DateTime.now(); // 2019-11-08 02:54:53.218443
var fiftyDaysAgo = today.add(new Duration(days: 5));
print('today加5天:$fiftyDaysAgo '); // today减5天:2019-11-03 02:54:53.218443
11.时间差(小时数)
var day1 = new DateTime(2019, 6, 20, 17, 30, 20);
var day2 = new DateTime(2019, 7, 21, 0, 0, 0);
print('比较两个时间 差 小时数:${day1.difference(day2)}'); // 比较两个时间 差 小时数:-726:29:40.000000
12.获取年、月、日、星期、时、分、秒、毫秒、微妙
year、month、day、weekday、hour、minute、second、millisecond、microsecond
var today = DateTime.now();
print(today.year);
13.获取本地时区简码
DateTime today = DateTime.now();
print('本地时区简码:${today.timeZoneName}'); // 本地时区简码:GMT
14.返回UTC与本地时差(小时数)
DateTime today = DateTime.now();
print('返回UTC与本地时差 小时数:${today.timeZoneOffset}');
边栏推荐
- A network security guinea pig's learning path - scripting of advanced usage of nmap
- OPENSSL基本实验以及OPENSSL详解
- 树莓派4b安装win11/10过程全教程(附蓝屏inaccessible boot device解决办法)
- Solve the problem that the 5+APP real machine test cannot access the background (same local area network)
- 记账凭证的种类、记账凭证的基本内容、记账凭证的填制要求、记账凭证的审核
- 备战金九银十:Android 高级架构师的学习路线及面试题分享
- 英语每日打卡
- 最简单的FRP内网穿透教程
- 快速搭建一个网关服务,动态路由、鉴权的流程,看完秒会(含流程图)
- c语言用栈实现计算中缀表达式
猜你喜欢
不懂“赚钱逻辑”,你永远都是社会最底层(广告电商)
mysql 原生语句点滴学习记录
记账凭证的种类、记账凭证的基本内容、记账凭证的填制要求、记账凭证的审核
(2) Sequence structures, Boolean values of objects, selection structures, loop structures, lists, dictionaries, tuples, sets
The first time to tear the code by hand, how to solve the problem of full arrangement
Win10 解决AMD平台下SVM无法开启的问题
关于我的大创、论文~
在 UUP dump 被墙的情况下如何用 UUP 下载 ISO 镜像
一个网络安全小白鼠的学习之路—nmap高级用法之脚本使用
云安全笔记:云原生全链路加密
随机推荐
Uniapp | compatibility problems in the development of (to be continued)
命令执行漏洞
Offensive and defensive world - novice MISC area 1-12
hackmyvm: kitty walkthrough
解密:链动2+1的商业模式
kotlin语法总结(二)
(2) Sequence structures, Boolean values of objects, selection structures, loop structures, lists, dictionaries, tuples, sets
关于我的项目-实现一个数据库~
Mysql创建索引
Summary of php function vulnerabilities
文件包含漏洞
一分钟get:缓存穿透、缓存击穿、缓存雪崩
聊聊MySQL的10大经典错误
对账、结账、错账更正方法、划线更正法、红字更正法、补充登记法
How to determine the direction based on two coordinate points on the map
Google Hacking
深入了解为何面试官常说:你还没准备好,我不会录用你
强化学习笔记:DDPG
关于我的项目-微信公众号~
最简单的FRP内网穿透教程