Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert String to TimeOfDay in flutter?

Tags:

flutter

dart

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.

like image 320
Daniel Castro Fernández Avatar asked Nov 19 '18 21:11

Daniel Castro Fernández


People also ask

How do you initialize TimeOfDay in Flutter?

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.

How do you convert 12 hours to 24 hour Flutter?

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.


1 Answers

Try this

TimeOfDay _startTime = TimeOfDay(hour:int.parse(s.split(":")[0]),minute: int.parse(s.split(":")[1]));

This Worked for me..

like image 104
z3r0c00l_2k Avatar answered Sep 20 '22 23:09

z3r0c00l_2k