假设我将 Timestamp
类型的对象设置为 2 天后。
如何在 dart 中及时获取 difference
,然后在 format
中DateFormat('hh : mm : ss')
?
答案 0 :(得分:1)
DateTime
构造一个 Timestamp
。DateTime
减去初始时间(我认为应该是 DateTime.now()
)得到 Duration
。Duration
。它的默认 .toString()
实现使用 hh:mm:ss.microseconds,这与您想要的很接近。如果您想要更多控制,you can easily format it yourself。var dateTime = DateTime.fromMicrosecondsSinceEpoch(timestamp.timestamp!);
var duration = dateTime.difference(DateTime.now());
print(duration);