I have a time picker that returns the TimeOfDay object. But I have to save that value in a database as an integer of milliseconds which obtained from DateTime.millisecondsSinceEpoch. How can I achieve that?
A value representing a time during the day, independent of the date that day might fall on or the time zone. The time is represented by hour and minute pair. Once created, both values cannot be changed. You can create TimeOfDay using the constructor which requires both hour and minute or using DateTime object.
How i Can convert 12 hour time string into 24 hour in flutter? 1. If you have dateTime or TimeOfDay type you can use intl package, otherwise here is my workaround. String time12to24Format (String time) { // var time = "12:01 AM"; int h = int.
_timeOfDay = await showTimePicker( context: context, initialTime: TimeOfDay. now(), ); DayPeriod dayPeriod = _timeOfDay!. period; print(dayPeriod); // This will return => DayPeriod.am/DayPeriod.pm as per the selection of time. } Save this answer.
This is not possible. TimeOfDay
holds only the hour and minute. While a DateTime
also has day/month/year
If you want to convert it, you will need more information. Such as the current DateTime. And then merge the two into one final datetime.
TimeOfDay t; final now = new DateTime.now(); return new DateTime(now.year, now.month, now.day, t.hour, t.minute);
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