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 :
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')));