如何在Flutter中读取Firestore时间戳 [英] How to read Firestore timestamp in Flutter
本文介绍了如何在Flutter中读取Firestore时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将Firestore时间戳更改为"2天前或1小时前"?我尝试直接显示它,但输出的数据是像Timestamp(seconds=1556459022, nanosecond=0)
这样的字符串.
How to change the firestore timestamp to something like "2 days ago or 1 hour ago" ? I tried displaying it directly but the data that came out was a string like Timestamp(seconds=1556459022, nanosecond=0)
.
该怎么做?
推荐答案
Firestore's timestamp has a toDate()
method that will return a dart DateTime
object.
由此您可以使用常规的dart解决方案,例如 timeago
库以将其显示为:
From that you can use regular dart solutions, like DateFormat
or the timeago
library to display it as in:
timeago.format(firestoreTimestamp.toDate());
这篇关于如何在Flutter中读取Firestore时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文