有没有一种好的方法将以毫秒为单位的时期时间(例如1486252500000,共13位数字)格式化为易于阅读的格式?
有没有一种好的方法将以毫秒为单位的时期时间(例如1486252500000,共13位数字)格式化为易于阅读的格式?
DateTime
有一个根据自纪元以来毫秒数的命名构造函数。
https://api.dartlang.org/stable/1.24.2/dart-core/DateTime/DateTime.fromMillisecondsSinceEpoch.html
DateTime date = new DateTime.fromMillisecondsSinceEpoch(1486252500000)
如果您想将其转换为人类可读的字符串,可以使用intl包中的DateFormat类。
import "package:intl/intl_browser.dart";
var format = new DateFormat("yMd");
var dateString = format.format(date);