How does Jekyll date formatting work?

I use Jekyll to create a simple site.

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

I found that through some kind of creative googling it manipulates the date format a bit, but nothing seems to give me the name of the month. I have {{ page.date| date: "%m-%d-%Y" }} {{ page.date| date: "%m-%d-%Y" }} , which displays me as 09-12-2011 , but not quite what I'm looking for.

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

Or, if it is not, is there any documentation for the date attribute?

+73
jekyll liquid
Sep 13 2018-11-11T00:
source share
5 answers

Decision

To create dates formatted like this:

 9 September 2013 

Use this output filter:

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

Note: the parameter - before the day parameter (i.e. %-d ) prevents the appearance of leading zeros in numbers below ten (i.e. 9 September 2013 instead of 09 September 2013 ).

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

More details

Dates can be formatted in almost any way. For example:

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

I have put together this large set of Jekyll date formatting examples showing how to produce them.

+132
Oct 27 2018-11-11T00:
source share

Jekyll adds filters to the fluid. See here . You can display the desired date format by simply running the date_to_long_string filter.

From the link:




Date in a long string

Format the date in a long format, for example. "January 27, 2011."

{{ site.time | date_to_long_string }} {{ site.time | date_to_long_string }} => 17 November 2008

+9
Mar 02 2018-12-12T00:
source share

Try "% B", which means "Full name of the month (` `January '')"

search for documentation for strftime, a function that is commonly used to convert a date to a string.

+3
Sep 13 2018-11-11T00:
source share

Use {{ page.date| date: "%d %B %Y" }} {{ page.date| date: "%d %B %Y" }} for dates like September 12, 2011, see the good and quick formatting guide on Jekyll Date Formatting

+2
Feb 28 '17 at 8:10
source share

Just in case, if you want to create your own solution, you can write the Jekyll plugin to format the date as you want, for example (this is an example for Italian dates):

 module Jekyll module ItalianDates MONTHS = {"01" => "gennaio", "02" => "febbraio", "03" => "marzo", "04" => "aprile", "05" => "maggio", "06" => "giugno", "07" => "luglio", "08" => "agosto", "09" => "settembre", "10" => "ottobre", "11" => "novembre", "12" => "dicembre"} # http://man7.org/linux/man-pages/man3/strftime.3.html def italianDate(date) day = time(date).strftime("%e") # leading zero is replaced by a space month = time(date).strftime("%m") year = time(date).strftime("%Y") day+' '+MONTHS[month]+' '+year end def html5date(date) day = time(date).strftime("%d") month = time(date).strftime("%m") year = time(date).strftime("%Y") year+'-'+month+'-'+day end end end Liquid::Template.register_filter(Jekyll::ItalianDates) 

Just save this in a file like _plugins/italian_dates.rb and use it as you need in the templates:

 <time datetime="{{page.date | html5date}}">{{page.date | italianDate}}</time> 
+1
Sep 01 '15 at 12:37
source share



All Articles