0

I should have two times, one is the current time and the other I get it from time picker as shown below.

How can I get the difference between them?

Code

Dale K
  • 25,246
  • 15
  • 42
  • 71
Nader Salah
  • 93
  • 1
  • 9

1 Answers1

0

You can use either of these two.

int getMinutesDiff(TimeOfDay tod1, TimeOfDay tod2) {
  return (tod1.hour * 60 + tod1.minute) - (tod2.hour * 60 + tod2.minute);
}

TimeOfDay getTimeOfDayDiff(TimeOfDay tod1, TimeOfDay tod2) {
  var minutes = (tod1.hour * 60 + tod1.minute) - (tod2.hour * 60 + tod2.minute);

  return TimeOfDay(hour: minutes ~/ 60, minute: minutes % 60);
}
kbaylosis
  • 308
  • 2
  • 9
  • Be aware that the difference between two times can depend on the date if you're in a place that observes daylight saving time. – jamesdlin Oct 25 '21 at 17:19