How to compare two dates that are constructed differently in Dart?

Technology CommunityCategory: FlutterHow to compare two dates that are constructed differently in Dart?
VietMX Staff asked 3 years ago

You can do that by converting the other date into utc and then comparing them with isAtSameMomentAs method.

void main(){
  String dateTime = '2020-02-03T08:30:00.000Z';
  int year = 2020;
  int month = 2;
  int day = 3;
  int hour = 8;
  int minute = 30;

  var dt = DateTime.utc(year,month,day,hour,minute);
  
  print(DateTime.parse(dateTime).isAtSameMomentAs(dt));
}