I need to show current time in 24-hours format in my Flutter project. Everything works perfect except that it will show 24:00 for 12am instead of showing 00:00. How can I solve this?
The below is my sample to format the date time:
DateFormat('kk:mm').format(time)
>Solution :
- You can fix that issue with use
Intlpackage, you can add it by
bellow commanddart pub add intl. - For more details you can refer this link.
-
Now we can format time to your requirements, look at bellow code example,
String formatTime() { DateTime dateTime = DateTime(2024, 1, 1, 0, 0); String formattedTime = DateFormat.Hm().format(dateTime); return formattedTime;}