最初,我为timestamp
字段使用了字符串格式,并且可以使用12 December 2017 2:34:23
将其转换为toData().toString()
格式。当字段timestamp
为timestamp
格式时,我需要做同样的事情。我可以在这方面获得帮助吗?
您可以使用]从时间戳获取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