读取时间戳字段并打印为2017年12月12日2:34:23

问题描述 投票:-1回答:1

最初,我为timestamp字段使用了字符串格式,并且可以使用12 December 2017 2:34:23将其转换为toData().toString()格式。当字段timestamptimestamp格式时,我需要做同样的事情。我可以在这方面获得帮助吗?

flutter timestamp
1个回答
0
投票

您可以使用]从时间戳获取DateTime变量。

var date = new DateTime.fromMicrosecondsSinceEpoch(timestamp);

一旦有了日期,您就可以格式化,但是例如您想使用DateFormat:

  var formatter = new DateFormat('yyyy-MM-dd'); // You can change the format here
  String formatted = formatter.format(date);
  print(formatted); // Something like 2019-04-20
© www.soinside.com 2019 - 2024. All rights reserved.