cho.sh
Displaying exact datetimes on Ghost

Displaying exact datetimes on Ghost

Warning

Over a year old. May be outdated

If your Ghost blog on a Handlebars theme shows dates like Published 11 months ago, your theme file has code like this.

hbs
<time datetime="{{date format="YYYY-MM-DD"}}">
  {{date published_at timeago="true"}}
</time>

Show exact date

The date published_at timeago="true" part makes it relative. Change it to this.

hbs
<time datetime="{{date format="YYYY-MM-DD"}}">
  {{date published_at format="MMMM DD, YYYY"}}
</time>

This will give something like September 7, 2000.

Show exact time

You can fine-tune with moment.js syntax.

hbs
<!-- 2000 September 07 9:00:00 PM -->
<time datetime="{{date format="YYYY-MM-DD hh:mm:ss A"}}">
  {{date published_at format="YYYY MMMM DD hh:mm:ss A"}}
</time>

<!-- 2000 09 07 9:00 PM -->
<time datetime="{{date format="YYYY-MM-DD hh:mm A"}}">
  {{date published_at format="YYYY MM DD hh:mm A"}}
</time>

<!-- 2000 09 07 21:00 -->
<time datetime="{{date format="YYYY-MM-DD hh:mm"}}">
  {{date published_at format="YYYY MM DD hh:mm"}}
</time>

For months, MM gives the short form (09) and MMMM gives the long one (September). Hours, minutes, seconds, and AM/PM work the same way if you want to display time. For example, I am using the following.

hbs
<time datetime="{{date format="YYYY-MM-DD h:mm A"}}">
  {{date published_at format="YYYY/MM/DD h:mm A"}}
</time>

Further

Backlinks1