Dart base language – Date and time

The statement

var now = new DateTime.now();
print(now);
var d = new DateTime(2018.10.10.9.30);
print(d);
Copy the code

Create time UTC

var d = new DateTime.utc(2018.10.10.9.30);
print(d);
Copy the code

Resolution time IOS 8601

var d1 = DateTime.parse('2018-10-10 09:30:30Z');
print(d1);
var d2 = DateTime.parse('the 2018-10-10 09:30:30 + 0800');
print(d2);
Copy the code

Time increases and decreases

var d1 = DateTime.now();
print(d1);
print(d1.add(new Duration(minutes: 5)));
print(d1.add(new Duration(minutes: - 5)));
Copy the code

More time

var d1 = new DateTime(2018.10.1);
var d2 = new DateTime(2018.10.10);
print(d1.isAfter(d2));
print(d1.isBefore(d2));
var d1 = DateTime.now();
var d2 = d1.add(new Duration(milliseconds: 30));
print(d1.isAtSameMomentAs(d2));
Copy the code

Time difference

var d1 = new DateTime(2018.10.1);
var d2 = new DateTime(2018.10.10);
var difference = d1.difference(d2);
print([difference.inDays, difference.inHours]);
Copy the code

The time stamp

var now = new DateTime.now();
print(now.millisecondsSinceEpoch);
print(now.microsecondsSinceEpoch);
Copy the code

PDF document sorting:

Dart Basic Language Learning – Part 1. PDF

Blog Source: Blog of rainy Night