malcommac / SwiftDate

🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.
MIT License
7.63k stars 770 forks source link

Question about date formatting with AM/PM and format set to `h:mm a` #736

Closed kazuooooo closed 4 years ago

kazuooooo commented 4 years ago

Hi, thank you for building very useful Library 😊

I noticed toFormat method is little bit strange. Code to reproduce here.

let a = "2020-05-20 00:00:00".toDate()
print(a?.toFormat("h:mm a")) // => Optional("12:00 AM")

It looks h and a are inconsistent.

I think it should be 12:00 PM or 0:00 AM. I am happy if you can help me 🙏

malcommac commented 4 years ago

It's correct; let's take a look at the Unicode Table for Date Formatting:

Screenshot 2020-09-16 at 16 25 46

you must pass a 0-23 time format, HH to obtain your result.