-
Hi, using Luxon to pretty print ISO 8601 dates in my application. I have tried both How can I force printing of 12 hour time? I'd like this to be at least an option in my application. Best, MJB |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Sure: DateTime
.now()
.setLocale("en-GB")
.toLocaleString({...DateTime.DATETIME_MED, "hourCycle": "h11"}) // => '15 May 2024, 1:40 pm' The argument to Note that you have to override it not because of anything about |
Beta Was this translation helpful? Give feedback.
-
@icambron Thanks for the swift reply, that got me sorted. Given that we also purchase fuel by the litre while measuring fuel efficiency in miles per gallon, I can understand the ICU's predicament. |
Beta Was this translation helpful? Give feedback.
Sure:
The argument to
toLocaleString()
is ultimately passed to theIntl.DateTimeFormat
constructor and thus supports everything that does.DateTime.DATETIME_MED
is just a precanned object containing formatting options. So you can just glom on extra options, as in my example.Note that you have to override it not because of anything about
DATETIME_MED
but actually because of theen-GB
locale, which does specify 24-hour time. In my locale ,en-US
, there's no debate and we always use 12-hour time, so the locale works like that by default. The UK seems…