Date
The date
helper can be used to format date and time values.
The first parameter is the datetime to format and the second is the format string; as a convenience various default formats are exposed to your templates to save constructing format strings for the common cases.
Which gives the result:
Thu Feb 11 2021
Specifying a format string is far from ideal so templates are passed a date.formats
object containing some useful pre-defined formats:
Which is equivalent to the explicit format example above.
Next we look at the built-in convenience formats; see the list of format specifiers for more information on creating your own formats.
You may configure format specifiers, see settings for more information.
Local
All datetime values are UTC if you want to account for the local time zone use the local
hash parameter:
Date
Here are all the built-in formats for date:
date-formats.date-short
: 2021-02-11date-formats.date-medium
: Thu Feb 11 2021date-formats.date-long
: Thursday February 11 2021
Time
Here are all the built-in formats for time:
date-formats.time-short
: 09:09date-formats.time-medium
: 09:09:54date-formats.time-long
: 09:09:54 AM
Both time-short
and time-medium
are the 24-hour clock; time-long
is the 12-hour clock.
Date & Time
Here are all the built-in formats for date and time:
date-formats.datetime-short
: 2021-02-11 01:09date-formats.datetime-medium
: Thu Feb 11 2021 01:09:54date-formats.datetime-long
: Thursday February 11 2021 01:09:54 AM