I have simple total hours and minutes. I need to add these
I am doing like this
TimeOfDay _time = TimeOfDay(hour: int.parse(hours.toString()), minute:int.parse(minutes.toString()));
But seems like its adding hours and minute on my current time. I need to add in 0 hours and 0 minutes.
For example, I have 12 hours
and 30 min
so it will just show 12:30
or if I have 12 hours
and 75 min
so it will show 13:15
CodePudding user response:
Are you looking for something like this?
TimeOfDay _calcTimeOfDay(int hour, int minute) {
if (minute > 60) {
minute = (minute % 60);
hour = 1;
}
return TimeOfDay(hour: hour, minute: minute);
}
The problem is if you have hour=24 and minute=75 then the hour would be 25, which is not a valid hour.
Not sure I fully understand the question, maybe if you can provide more info.
CodePudding user response:
Use this code this will work for you
utcTo12HourFormat() {
//DateTime(year, month, day, hour, minute, second, millisecond, microsecond)
var time = TimeOfDay.fromDateTime(DateTime(2021, 9, 23, 12, 75));
print(time.hour.toString() ':' time.minute.toString());
}
You can also visit this link for more information