Skip to content

How to format dates with recommended AP style a.m. and p.m. #13616

Closed Answered by brandonkelly
laurabennett asked this question in Q&A
Discussion options

You must be logged in to vote

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 the replace filter:

{{ now|datetime|replace({
  AM: 'A.M.',
  PM: 'P.M.',
}) }}

You could throw that in a macro to keep your templates DRY:

{% macro datetime(date) …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants