Dart-将自纪元以来的毫秒数(UNIX时间戳)转换为人类可读的时间 [英] Dart - Converting Milliseconds Since Epoch (UNIX timestamp) into human readable time

查看:542
本文介绍了Dart-将自纪元以来的毫秒数(UNIX时间戳)转换为人类可读的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从纪元(例如1486252500000 13位数字)将时间格式化为人类可读格式以来,是否存在一种解析毫秒的好方法?

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

推荐答案

DateTime 确实有一个自时期以来毫秒的命名构造函数

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)

如果要将其转换为人类可读的字符串,可以使用 intl 包和 DateFormat

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);

这篇关于Dart-将自纪元以来的毫秒数(UNIX时间戳)转换为人类可读的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆