flutter timeofday calculations

2019-07-26 07:38发布

问题:

in my flutter app the user picks a time and I need to simply add some hours and minute to it to display the result. Is that easily possible? Unfortunately, there doesn't seem to be a function like TimeOfDay.add().

Any ideas?

Thanks!

回答1:

You can Use Date Time for that: You can add Minutes or Hours as you like.

TimeOfDay.fromDateTime(DateTime.now().add(Duration(hours: 2))); // result is 2hrs ahead of current time