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)
Intl
package, you can add it by
bellow command dart pub add intl
.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;}