flutter 日期、时间、日期格式化库、Future类型方法

日期
 DateTime 日期对象 = new DateTime.now();
 
	 日期对象       打印本身会返回年月日和时分秒的字符串
	 日期对象.year  获取年等
	 日期对象.millisecondsSinceEpoch    当前时间的时间戳
	 DateTime.fromMillisecondsSinceEpoch(时间戳);  将时间戳转换成日期

时间
var xx=TimeOfDay(hour: n,minute: n2);
	将返回: TimeOfDay(19:40)
	xx.format(context)  返回7:40 PM形式的字符串,必须在 Widget build方法中使用

日期格式化库date_format
	去dart库中下载,按教程引入
	
		formatDate(DateTime(1989, 02, 21), [yyyy, '-', mm, '-', dd])    1989-02-21
		第一个参数也可以直接是时间对象

Future类型方法
	和promise方法相似,可以使用.then((x){xx})方法接收返回值或await接收返回值
发布了670 篇原创文章 · 获赞 4 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_43294560/article/details/105589797