How to format dates with recommended AP style a.m. and p.m. #13616
-
#4558 mentions that en-GB formats with the dot style which is interesting but I don't want to change everything to "British". Is there a way to use the dot format? Looks like PHP only give uppercase or lowercase am or AM. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The exact date/time formats come from the ICU library installed on the server, which is a massive database that tells apps like Craft how they should handle several aspects of internationalization, including how to format dates/times. So not something Craft should have a ton of control over. (And the locale data export mentioned in #4558 (comment) is no longer a thing in Craft 4, as the Intl extension (which provides an API for the ICU DB) is now a strict requirement.) Probably the easiest way to force adding {{ now|datetime|replace({
AM: 'A.M.',
PM: 'P.M.',
}) }} You could throw that in a macro to keep your templates DRY: {% macro datetime(date) %}
{{ date|datetime|replace({
AM: 'A.M.',
PM: 'P.M.',
}) }}
{% endmacro %}
...
{{ _self.datetime(now) }}
{{ _self.datetime(entry.postDate) }} |
Beta Was this translation helpful? Give feedback.
The exact date/time formats come from the ICU library installed on the server, which is a massive database that tells apps like Craft how they should handle several aspects of internationalization, including how to format dates/times. So not something Craft should have a ton of control over. (And the locale data export mentioned in #4558 (comment) is no longer a thing in Craft 4, as the Intl extension (which provides an API for the ICU DB) is now a strict requirement.)
Probably the easiest way to force adding
.
s would be using thereplace
filter:You could throw that in a macro to keep your templates DRY: