Option to format date

Please create option to format the date to match local formats.

Post template of the of the Source theme.

<time class="gh-article-meta-date" datetime="{{date format="YYYY-MM-DD"}}">{{date format="D MMM YYY"}}</time>

Not entirely sure what specifically you mean.

If you’re looking for a way to change the standard formatting, based on the post template, you can edit the “format” string.

If you’re looking for something that adapts to your visitor’s browser locale, you can add this as a code injection to your Ghost site:

<script>
  document.addEventListener('DOMContentLoaded', (event) => {
  document.querySelectorAll('.gh-article-meta-date').forEach(function(el) {
    let date = new Date(el.getAttribute('datetime'));
    let formattedDate = new Intl.DateTimeFormat().format(date);

    el.textContent = formattedDate;
  });
});
</script>

It’s a snippet that waits for the site to be fully loaded, then fetches the date from within the .gh-article-meta-date, formats it according to the browser’s locale, and overwrites the text value.

2 Likes

Brilliant. Thank you.

1 Like