Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show current time in 24 hours format in Flutter, not using AM or PM? [duplicate]

Tags:

flutter

dart

how can I show the time format in 24 hours in flutter, but not using AM or PM, like if there is afternoon 1 o'clock the how can i show is 13 hours ago. Please suggest me.

like image 841
Shahid jafrey Avatar asked Aug 08 '20 10:08

Shahid jafrey


People also ask

How do I change time format on Flutter?

To format DateTime in Flutter using a standard format, you need to use the intl library and then use the named constructors from the DateFormat class. Simply write the named constructor and then call the format() method with providing the DateTime.

How do you convert 12 hours to 24 hours in 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

You can use DateFormat from intl package and use HH to show hours in 24-hours format:

var now = DateTime.now();
print(DateFormat('HH:mm:ss').format(now));

Result:

14:43:41
like image 63
Mobina Avatar answered Oct 21 '22 04:10

Mobina