void main(List<String> args) {
// Define two dates.
DateTime date1 = new DateTime(2010, 1, 1, 8, 0, 15);
DateTime date2 = new DateTime(2010, 8, 18, 13, 30, 30);
// Calculate the interval between the two dates.
Duration interval = date2.difference(date1);
print('$date2 - $date1 = $interval');
// Display individual properties of the resulting TimeSpan object.
print('Total Number of Days: ${interval.inDays}');
print('Total Number of Hours: ${interval.inHours}');
print('Total Number of Minutes: ${interval.inMinutes}');
print('Total Number of Seconds: ${interval.inSeconds}');
print('Total Number of Milliseconds: ${interval.inMilliseconds}');
}
结果将是:
2010-08-18 13:30:30.000 - 2010-01-01 08:00:15.000 = 5501:30:15.000000
Total Number of Days: 229
Total Number of Hours: 5501
Total Number of Minutes: 330090
Total Number of Seconds: 19805415
Total Number of Milliseconds: 19805415000
2条答案
按热度按时间pbpqsu0x1#
它是Duration。
例如:
结果将是:
yduiuuwa2#
在Flutter/Dart应用中从C# Timespan字符串Map到持续时间
如果您有一个基于C#的API/服务器,它提供具有TimeSpan属性的数据传输对象,则在客户端阅读Dart/Flutter应用程序中的数据可能是一个挑战,因为Dart当前不提供Duration parse()函数。TimeSpan字符串格式为[-]d.hh:mm:ss.ff
下面的代码提供了一个解析方法,它可以用两种不同的模式实现(可以选择String扩展或DurationExt方法),test 类展示了如何使用这两种模式构建fromMap()解决方案: