How to show time in AM or PM format from TimeOfDay with flutter?
Once you have the time selected, you can format it with new DateFormat.jm()
, which will output, for example, 5:00 PM
. See DateFormat docs for more.
Edit: You could do this a few ways.
One way is to use a function, like this:
String formatTimeOfDay(TimeOfDay tod) { final now = new DateTime.now(); final dt = DateTime(now.year, now.month, now.day, tod.hour, tod.minute); final format = DateFormat.jm(); //"6:00 AM" return format.format(dt);}
Another way is to use this is in the example provided from the docs:
print(new DateFormat.yMMMd().format(new DateTime.now()));