Jekyll One

QuickSearch

This guide provides examples for time and date formats on a Jekyll site that can be used for J1 Theme. The examples provided on this page are tested code snippets for displaying several date formats on a Jekyll site. They should also work on Jekyll-based GitHub Pages, or anything else that uses the Liquid template engine.

Predefined Date Filters

The examples provided on this page are tested code snippets for displaying several date formats on a Jekyll site. They should also work on Jekyll-based GitHub Pages, or anything else that uses the Liquid template engine.

More details of the Template Engine Liquid can be found on page Liquid User Guide.

Displaying Time and Date is done for example by using the Liquid output markup like:

{{ page.date }}

With no other alteration, a Date string generated looks something like:

2022-01-01

If there are designs that use that format, they are few and far between. Creating friendlier-looking dates is done by applying Liquid’s date filter. For example, the filter combination:

{{ page.date | date: '%B %d, %Y' }}

produces more reader-friendly date like so:

January 01, 2022

The following set of Liquid date filters solves common issues in formatting strings for Date/Time and explores a few other formatting options. Each one provides a solution for a specific display format.

Liquid supports some standard filter to define common date formats.

Table 1. Predefined Date Filters
Filter Markup Example

date_to_string

page.date | date_to_string

01 Jan 2022

date_to_long_string

page.date | date_to_long_string

01 January 2022

date_to_xmlschema

page.date | date_to_xmlschema

2022-01-01T00:00:00+01:00

date_to_rfc822

page.date | date_to_rfc822

Sat, 01 Jan 2022 00:00:00 +0100

Combined Date Filters

Beside predefined date formats, the filter date: accepts all formatting pattern defined in the ISO 8601 standard. Find very common Time and Date formats below.

Table 2. Combined Date Filters
Filter Markup Example

ISO 8601 Date

page.date | date: '%Y-%m-%d'

2022-01-01

Four digit Year

page.date | date: '%m/%d/%Y'

01/01/2022

Two digit Year

page.date | date: '%-m/%-d/%y'

1/1/22

Full Month name

page.date | date: '%B %-d, %Y'

January 1, 2022

Non-US full Month name

page.date | date: '%-d %B %Y'

1 January 2022

Full Month name

page.date | date: '%B %-d, %Y'

January 1, 2022

Full Day and Month name

page.date | date: '%A, %B %-d, %Y'

Saturday, January 1, 2022

Much more formatting for Time and Date can be done using the date: filter. The next section offers a comprghensive list of patterns and pattern combinations to create Date and Time strings for every use case.

ISO 8601 Time and Date

This ISO 8601 standard helps remove doubts that can result from the various day–date conventions, cultures and time zones that impact a global operation. It gives a way of presenting dates and times that is clearly defined and understandable to both: people and machines.

Common ISO 8601 Time and Date pattern

Common ISO 8601 formats available for Time and Date.

Table 3. Common ISO 8601 Time and Date pattern
Format Description Example

%Y-%m-%d | %F

Calendar date

1979-04-25

%Y-%m

Calendar date, specific month

1990-04

%Y

Calendar date, specific year

1956

%C

Calendar date, specific century

20

%Y-%j

Ordinal date

1988-295

%G-W%V-%u

Week date

1955-W16-3

%G-W%V

Week date, specific week

1955-W43

%H:%M:%S | %T

Local time, full

00:00:00

%H:%M

Local time, reduced

00:00

%H

Local time, specific hour

00

%T,%L

Local time with decimal fraction, comma as decimal sign

00:00:00

%T.%L

Local time with decimal fraction, full stop as decimal sign

00:00:00.000

%T%:z

Local time and the difference from UTC

00:00:00+01:00

%FT%T%:z

Date and time of day for calendar date

2005-01-05T00:00:00+01:00

%Y-%jT%T%:z

Date and time of day for ordinal date

`2001-204T00:00:00+02:00

%G-W%V-%uT%T%:z

Date and time of day for week date

1978-W16-1T00:00:00+01:00

%FT%R

Calendar date and local time

1988-04-29T00:00

%Y-%jT%RZ

Ordinal date and UTC of day

1998-242T00:00Z

%G-W%V-%uT%R%:z

Week date and local time and difference from UTC

1954-W16-2T00:00+01:00

Year, Month, and Day

Year, Month, and Day shortcuts of ISO 8601.

Table 4. Year, Month, and Day pattern
Format Description Example

%Y

Year with century if provided, will pad result at least 4 digits

1988

%C

Year / 100 (rounded down such as 20 in 2022)

19

%y

Year % 100 (00..99)

76

%m

Month of the year, zero-padded (01..12)

03

%-m

Month of the year, no padding (1..12)

10

%B

The full month name

January

%^B

The full month name uppercase

NOVEMBER

%b

The abbreviated month name

Nov

%^b

The abbreviated month name uppercase

JAN

%h

%h - Equivalent to %b

Jul

%d

Day of the month, zero-padded (01..31)

20

%-d | %e

Day of the month, no padding (1..31)

21

%j

Day of the year (001..365)

353

%-j

Day of the year no padding (1..365)

189

Hour, Minute, and Second

Hour, Minute, Second and Subsecond shortcuts of ISO 8601.

Table 5. Hour, Minute, and Second pattern
Format Description Example

%H

Hour of the day, 24-hour clock, zero-padded (00..23)

00

%k

Hour of the day, 24-hour clock, blank-padded (0..23)

0

%I

Hour of the day, 12-hour clock, zero-padded (01..12)

12

%l

Hour of the day, 12-hour clock, blank-padded (1..12)

12

%p

Meridian indicator, uppercase (AM or PM)

AM

%P

Meridian indicator, lowercase (am or pm)

am

%M

Minute of the hour (00..59)

00

%S

Second of the minute (00..60)

00

%L

Millisecond of the second (000..999). The digits under millisecond are truncated to not produce 1000.

000

%N

Fractional seconds digits, default is 9 digits (nanosecond).

  • %3N millisecond (3 digits)

  • %6N microsecond (6 digits)

  • %9N nanosecond (9 digits)

  • %12N picosecond (12 digits)

  • %15N femtosecond (15 digits)

  • %18N attosecond (18 digits)

  • %21N zeptosecond (21 digits)

  • %24N yoctosecond (24 digits)

The digits under the specified length are truncated to avoid carry up.

000000000

Time zone

Time zone shortcuts of ISO 8601.

Table 6. Time zone shortcuts
Format Description Example

%z

Time zone as hour and minute offset from UTC

+0100

%:z

Hour and minute offset from UTC with a colon

+01:00

%::z

Hour, minute and second offset from UTC

+02:00:00

%Z

Abbreviated time zone name or similar information.
NOTE: The abbreviated time zone name is OS dependent.

CEST

Weekday

Weekday shortcuts of ISO 8601.

Table 7. Weekday shortcuts
Format Description Example

%A

The full weekday name

Saturday

%^A

The full weekday name uppercase

SATURDAY

%a

The abbreviated weekday name

Sun

%^a

The abbreviated weekday name uppercase

TUE

%u

Day of the week (1..7)

Monday is 1

1

%w

Day of the week (0..6)

Sunday is 0

1

Week number

The first week of YYYY that starts with a Sunday or Monday (according to %U or %W). The days in the year before the first week are in week 0.

Table 8. Week number
Format Description Example

%U

Week number of the year. The week starts with Sunday. (00..53)

34

%W

Week number of the year. The week starts with Monday. (00..53)

08

Seconds since the Epoch

The Unix epoch is the number of seconds that have elapsed since January 1, 1970 at midnight UTC time minus the leap seconds. This means that at midnight of January 1, 1970, Unix time was 0.

Table 9. Seconds since the Epoch
Format Description Example

%s

Number of seconds since 1970-01-01 00:00:00 UTC.

1659715076, means 5. August 2022 15:57:29

Literal strings

For formatting time and date strings, the following literal strings are available.

Table 10. Literal strings
Format Description Example

%n

Newline character (\n)

\n

%t

Tab character (\t)

\t

%%

Literal % character

%

Predefined Time and Date pattern

Some common Time and Date pattern are available as predefined pattern combinations.

Table 11. Predefined Time and Date pattern
Format Description Example

%c

Date and Time (%a %b %e %T %Y)

Fri Dec 15 00:00:00 1950

%D

Date (%m/%d/%y)

01/11/81

%F

The ISO 8601 Date format (%Y-%m-%d)

1986-04-27

%R

24-hour Time (%H:%M)

00:00

%T

24-hour Time (%H:%M:%S)

00:00:00

%x

Same as %D (%m/%d/%y)

07/13/63

%X

Same as %T (%H:%M:%S)

00:00:00