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.
Filter | Markup | Example |
---|---|---|
| page.date | date_to_string | 01 Jan 2022 |
| page.date | date_to_long_string | 01 January 2022 |
| page.date | date_to_xmlschema | 2022-01-01T00:00:00+01:00 |
| 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.
Filter | Markup | Example |
---|---|---|
| page.date | date: '%Y-%m-%d' | 2022-01-01 |
| page.date | date: '%m/%d/%Y' | 01/01/2022 |
| page.date | date: '%-m/%-d/%y' | 1/1/22 |
| page.date | date: '%B %-d, %Y' | January 1, 2022 |
| page.date | date: '%-d %B %Y' | 1 January 2022 |
| page.date | date: '%B %-d, %Y' | January 1, 2022 |
| 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.
Format | Description | Example |
---|---|---|
| Calendar date | 1995-11-02 |
| Calendar date, specific month | 1971-12 |
| Calendar date, specific year | 2003 |
| Calendar date, specific century | 19 |
| Ordinal date | 1951-357 |
| Week date | 1966-W17-1 |
| Week date, specific week | 1998-W27 |
| Local time, full | 00:00:00 |
| Local time, reduced | 00:00 |
| Local time, specific hour | 00 |
| Local time with decimal fraction, comma as decimal sign | 00:00:00 |
| Local time with decimal fraction, full stop as decimal sign | 00:00:00.000 |
| Local time and the difference from UTC | 00:00:00+01:00 |
| Date and time of day for calendar date | 1988-04-12T00:00:00+02:00 |
| Date and time of day for ordinal date | `1958-347T00:00:00+01:00 |
| Date and time of day for week date | 1995-W19-3T00:00:00+02:00 |
| Calendar date and local time | 1995-10-15T00:00 |
| Ordinal date and UTC of day | 1997-256T00:00Z |
| Week date and local time and difference from UTC | 1991-W14-3T00:00+02:00 |
Year, Month, and Day
Year, Month, and Day shortcuts of ISO 8601
.
Format | Description | Example |
---|---|---|
| Year with century if provided, will pad result at least 4 digits | 2006 |
| Year / 100 (rounded down such as 20 in 2022) | 19 |
| Year % 100 (00..99) | 04 |
| Month of the year, zero-padded (01..12) | 01 |
| Month of the year, no padding (1..12) | 7 |
| The full month name | June |
| The full month name uppercase | OCTOBER |
| The abbreviated month name | Apr |
| The abbreviated month name uppercase | OCT |
| %h - Equivalent to %b | May |
| Day of the month, zero-padded (01..31) | 24 |
| Day of the month, no padding (1..31) | 29 |
| Day of the year (001..365) | 088 |
| Day of the year no padding (1..365) | 136 |
Hour, Minute, and Second
Hour, Minute, Second and Subsecond shortcuts of ISO 8601
.
Format | Description | Example | ||
---|---|---|---|---|
| Hour of the day, 24-hour clock, zero-padded (00..23) | 00 | ||
| Hour of the day, 24-hour clock, blank-padded (0..23) | 0 | ||
| Hour of the day, 12-hour clock, zero-padded (01..12) | 12 | ||
| Hour of the day, 12-hour clock, blank-padded (1..12) | 12 | ||
| Meridian indicator, uppercase (AM or PM) | AM | ||
| Meridian indicator, lowercase (am or pm) | am | ||
| Minute of the hour (00..59) | 00 | ||
| Second of the minute (00..60) | 00 | ||
| Millisecond of the second (000..999). The digits under millisecond are truncated to not produce 1000. | 000 | ||
| Fractional seconds digits, default is 9 digits (nanosecond).
| 000000000 |
Time zone
Time zone shortcuts of ISO 8601
.
Format | Description | Example |
---|---|---|
| Time zone as hour and minute offset from UTC | +0200 |
| Hour and minute offset from UTC with a colon | +01:00 |
| Hour, minute and second offset from UTC | +01:00:00 |
| Abbreviated time zone name or similar information. | CET |
Weekday
Weekday shortcuts of ISO 8601
.
Format | Description | Example | ||
---|---|---|---|---|
| The full weekday name | Wednesday | ||
| The full weekday name uppercase | TUESDAY | ||
| The abbreviated weekday name | Sun | ||
| The abbreviated weekday name uppercase | TUE | ||
| Day of the week (1..7)
| 3 | ||
| Day of the week (0..6)
| 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.
Format | Description | Example |
---|---|---|
| Week number of the year. The week starts with Sunday. (00..53) | 05 |
| Week number of the year. The week starts with Monday. (00..53) | 15 |
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.
Format | Description | Example |
---|---|---|
| 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.
Format | Description | Example |
---|---|---|
| Newline character (\n) | \n |
| Tab character (\t) | \t |
| Literal % character | % |
Predefined Time and Date pattern
Some common Time and Date pattern are available as predefined pattern combinations.
Format | Description | Example |
---|---|---|
| Date and Time (%a %b %e %T %Y) | Tue Sep 7 00:00:00 2004 |
| Date (%m/%d/%y) | 02/14/93 |
| The ISO 8601 Date format (%Y-%m-%d) | 1977-08-06 |
| 24-hour Time (%H:%M) | 00:00 |
| 24-hour Time (%H:%M:%S) | 00:00:00 |
| Same as %D (%m/%d/%y) | 10/15/65 |
| Same as %T (%H:%M:%S) | 00:00:00 |