Flutter 有没有办法制作动态时间戳,打印 10 分钟前、1 小时前或 2 个月前的内容
我已经将我的lastseen时间戳发送到firebase中,如何用我已经发送到firestore的时间戳来扣除当前时间戳。这会给我Last Seen 15 分钟前
,或者可能是很长一段时间,看起来像Last Seen 20 days ago
那样。我已经尝试在 pub.dev 中使用 timeago
包,但我不知道在持续时间内应该替换什么。代码看起来像这样
final fifteenAgo = DateTime.now().subtract(Duration(minutes: 15));
我应该用什么替换分钟?
这是我从 firestore 检索到的数据
I/flutter ( 6086): 2022-03-24 12:21:32.235192
i already send my lastseen timestamp into firebase and how can i deduct the current timestamp with the one that i already sent to firestore. that will give me Last Seen 15 minutes ago
, or maybe a long time that look like this Last Seen 20 days ago
that did it. im already try to use the timeago
package in pub.dev but i dont know what should i replace in the duration. the code look like this
final fifteenAgo = DateTime.now().subtract(Duration(minutes: 15));
what should i replace the minutes with ?
this is the data that i've been retrieve from firestore
I/flutter ( 6086): 2022-03-24 12:21:32.235192
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
timePassed 变量将保存自上次查看以来经过的持续时间。然后,您必须定义一个函数,该函数获取持续时间并返回应显示的正确字符串,例如“5 天前”或其他内容。
The timePassed variable will then hold the duration that passed since it was last seen. You will then have to define a function that takes the duration and returns the proper string that should be displayed like for example "5 days ago" or something else.