What data type is used in dart instead of the TimeSpan data type in C#?
CodePudding user response:
It is Duration.
For example:
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}');
}
the result will be:
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
