Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 在颤振中显示两个Firestore时间戳值之间的差异_Flutter_Dart_Google Cloud Firestore_Timestamp - Fatal编程技术网

Flutter 在颤振中显示两个Firestore时间戳值之间的差异

Flutter 在颤振中显示两个Firestore时间戳值之间的差异,flutter,dart,google-cloud-firestore,timestamp,Flutter,Dart,Google Cloud Firestore,Timestamp,我将startdate和endDate作为用户的输入,DateTime作为颤振(Dart)中的数据类型。这些字段将以时间戳格式存储在Firestore中。 现在我们需要在客户端显示endDate和startDate的差异,它可以是一个实时计时器,格式为“13小时45分钟”,然后在一些分钟后,它应该是“13小时42分钟” 我可以知道我们如何使用Firestore实现这一点,或者可能是针对Flitter应用程序的云功能? 感谢在flatter中,时间戳可以很容易地转换为日期时间,并且日期时间有一种称

我将startdate和endDate作为用户的输入,DateTime作为颤振(Dart)中的数据类型。这些字段将以时间戳格式存储在Firestore中。 现在我们需要在客户端显示endDate和startDate的差异,它可以是一个实时计时器,格式为“13小时45分钟”,然后在一些分钟后,它应该是“13小时42分钟”

我可以知道我们如何使用Firestore实现这一点,或者可能是针对Flitter应用程序的云功能?
感谢在flatter中,
时间戳
可以很容易地转换为
日期时间
,并且
日期时间
有一种称为
差异
的方便方法,它可以将两个
日期时间
对象之间的差异作为
持续时间
对象

下面是一个简单的例子:

final Timestamp endTime = Timestamp(1000, 0);
final Timestamp startTime = Timestamp(500, 0);
final DateTime endTimeDate = endTime.toDate();
final DateTime startTimeDate = startTime.toDate();
final Duration difference = endTimeDate.difference(startTimeDate);

谢谢你。我以日期时间格式输入如下:-selectedStartDate=2021-01-03 10:41:00.000 selectedEndDate=2021-01-05 16:41:00.000,我得到的差异持续时间为:54:00:00.000000,因此我的首选输出应为54小时00分钟。你能帮我怎么做吗?@Akshay你可以这样做: