Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

  • 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;}
    
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading