How to show 00:00 (24hrs format) for 12am instead 24:00 in flutter

51 views Asked by At

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)
1

There are 1 answers

0
K.D.Dilshan On BEST ANSWER
  • You can fix that issue with use Intl package, you can add it by bellow command dart 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;}