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

Intl package makes mistakes with converting 12:00 PM/ 12:00 AM into 24 hours

I’m trying to covert dates like 09:00 AM into 24 hours it works perfect with the intl package but I’m getting only one issue that the date 12:00 PM it convert it to 00:00 and 12:00 AM it convert it to 12:00 otherwise all other dates works perfect.

 print(DateFormat.Hm()
          .format(DateFormat("HH:mm a").parse('12:00 PM'))); // doesn't work => it prints 00:00

 print(DateFormat.Hm()
          .format(DateFormat("HH:mm a").parse('12:00 AM'))); // doesn't work it prints 12:00

print(DateFormat.Hm()
          .format(DateFormat("HH:mm a").parse('09:00 PM')));// works => 21:00

>Solution :

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

use h instead of H

h hour in am/pm (1~12) (Number) 12

H hour in day (0~23) (Number) 0

https://api.flutter.dev/flutter/intl/DateFormat-class.html

print(DateFormat.Hm()
          .format(DateFormat("hh:mm a").parse('12:00 PM')));

print(DateFormat.Hm()
          .format(DateFormat("hh:mm a").parse('12:00 AM'))); 

print(DateFormat.Hm()
          .format(DateFormat("hh:mm a").parse('09:00 PM')));
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