Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Jekyll date formatting work?

Tags:

jekyll

liquid

I'm using Jekyll to generate a simple site.

I want the date field to display in the format 12 September 2011.

I've found, through some creative googling, a bit of date-format manipulation, but nothing that seems to get me the month name. What I have is {{ page.date| date: "%m-%d-%Y" }}, which gets me output as 09-12-2011, but isn't quite what I'm looking for.

Is there any way to get the month as a name in Jekyll?

Or, barring that, is there any documentation for the date attribute?

like image 835
Michael Avatar asked Sep 13 '11 00:09

Michael


People also ask

How is a date formatted?

The international standard recommends writing the date as year, then month, then the day: YYYY-MM-DD.

What is DDD in date format?

The "ddd" custom format specifier represents the abbreviated name of the day of the week. The localized abbreviated name of the day of the week is retrieved from the DateTimeFormatInfo.


Video Answer


1 Answers

Solution

This output filter:

{{ page.date | date: "%-d %B %Y" }} 

produces dates formatted like:

9 September 2013 

Be sure not to miss the minus (-) in front of %-d for the day. Without it, numbers below ten would have leading zeros (e.g. 09 September 2013).

Details on the individual date formatting tokens can be found on the Liquid "Output tags and filters" documentation page.

More Info

I put together a large set of Jekyll date formatting examples. It provides examples for several formats and should provide enough detail to format in any way you'd like. Some examples include:

  • 2013-09-23
  • September 23, 2013
  • Sept. 23rd, 2013
  • 4 Juli 2013 (i.e. changing names to other languages like "Juli" instead of "July").

Enjoy!

like image 141
Alan W. Smith Avatar answered Sep 22 '22 12:09

Alan W. Smith