Home > Software engineering >  mysql timestamp calculations in dart
mysql timestamp calculations in dart

Time:04-06

I am getting 2 timestamps in my Flutter/Dart app via an API in the following format:

2022-04-05 10:00:00 / 2022-04-05 12:00:00

I would like to calculate the time difference of the two and round it to one decimal place.

How do I do this using dart?

CodePudding user response:

You can try something like this with the intl package.

import 'package:intl/intl.dart';

void main() {
 
  DateFormat formatter =  DateFormat("y-M-d H:m:s");
  var date_a = formatter.parse("2022-04-05 10:00:00");
  var date_b = formatter.parse("2022-04-05 12:00:00");
 
  print(date_b.difference(date_a));

}

Reference: https://pub.dev/documentation/intl/latest/intl/intl-library.html

  • Related