AP style month abbreviations with strftime in Liquid
AP style is particular about how dates are formatted in various circumstances. strftime
uses %b
for month abbreviations, but its format (the first three letters of the month: Jan, Feb, etc) differs from AP style’s preferred abbreviations for some months. This Liquid snippet converts strftime
’s month abbreviations to AP style:
{{ object | date: '%b. %e, %Y' | replace: 'Mar.', 'March' | replace: 'Apr.', 'April' | replace: 'May.', 'May' | replace: 'Jun.', 'June' | replace: 'Jul.', 'July' | replace: 'Sep.', 'Sept.' }}
For example, this Liquid code…
{% assign today = '2020-09-15' %}
<p class="current-date">{{ today | date: '%b. %e, %Y' | replace: 'Mar.', 'March' | replace: 'Apr.', 'April' | replace: 'May.', 'May' | replace: 'Jun.', 'June' | replace: 'Jul.', 'July' | replace: 'Sep.', 'Sept.' }}</p>
…will generate this HTML:
<p class="current-date">Sept. 15, 2020</p>