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.
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.
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.
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
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