Dart - Converting Milliseconds Since Epoch (UNIX timestamp) into human readable time

对着背影说爱祢 提交于 2020-08-02 06:19:07

问题


Is there a good way to parse milliseconds since epoch (ex. 1486252500000 13 digits) formatted time into a human readable format?


回答1:


DateTime does have a named constructor for millisecond since epoch

https://api.dartlang.org/stable/1.24.2/dart-core/DateTime/DateTime.fromMillisecondsSinceEpoch.html

DateTime date = new DateTime.fromMillisecondsSinceEpoch(1486252500000)

If you want to convert it to human readable string, you can use intl package with the DateFormat class

import "package:intl/intl_browser.dart";

var format = new DateFormat("yMd");
var dateString = format.format(date);


来源:https://stackoverflow.com/questions/45357520/dart-converting-milliseconds-since-epoch-unix-timestamp-into-human-readable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!