I have a String, lets say '16:00' and I want to convert it to a TimeOfDay type. I checked the documentation and it only provides a conversor from DateTime to TimeOfDay, but I cant find a way to convert from String to TimeOfDay.
You can create TimeOfDay using the constructor which requires both hour and minute or using DateTime object. Hours are specified between 0 and 23, as in a 24-hour clock. See also: showTimePicker, which returns this type.
Convert it to 24 hours format If we set alwaysUse24HourFormat to true, it might convert to 24 hours format but we need to clone the default setting and then change the value in somewhere.
Try this
TimeOfDay _startTime = TimeOfDay(hour:int.parse(s.split(":")[0]),minute: int.parse(s.split(":")[1]));
This Worked for me..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With