这就是我获取DateTime值以查看示例输出的地方。
@override
Widget build(BuildContext context) {
print('Datetime UTC: ${DateTime.now().toUtc()}');
print('Date from Json: $date');
print('Time ago from Json: ${timeago.format(date)}');
print('Time ago from Json using UTC: ${timeago.format(date, clock: DateTime.now().toUtc())}');
return GestureDetector(...这就变成了输出显示。我现在的时间是2020-03-07 09:42Time "Time ago from Json:“是正确的,但"Time ago from Json using UTC:”是不正确的。
I/flutter (27117): Datetime UTC: 2020-03-07 01:42:59.742488Z
I/flutter (27117): Date from Json: 2020-03-07 00:32:31.000
I/flutter (27117): Time ago from Json: 9 hours ago
I/flutter (27117): Time ago from Json using UTC: 9 hours ago相同的输出,使用timeago包
发布于 2020-06-17 19:28:56
var currentTime = DateTime.now();
var jsonTime = $date
print(timeago.format(currentTime.subtract(jsonTime));如果你看一下timeago.format()的参数,你会发现它接受了一个Duration作为参数。
https://stackoverflow.com/questions/60573681
复制相似问题