v1.9.1
Converts a timestamp into another date format. LiquidJS tries to be conformant with Shopify/Liquid which is using Ruby’s core Time#strftime(string). The input is firstly converted to Date
object via new Date().
Input
{{ article.published_at | date: "%a, %b %d, %y" }}
Output
Fri, Jul 17, 15
TimeZoneDate will be converted to local time before output. To avoid that, you can set
timezoneOffset
LiquidJS option to0
, its default value is your local timezone offset which can be obtained bynew Date().getTimezoneOffset()
.
And you can set a timezone for each individual date
filter via the second parameter:
Input
{{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", 360}} // equivalent to setting `options.timezoneOffset` to `360`.
{{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", "Asia/Colombo" }}
Output
1990-12-31T17:00:00
1991-01-01T04:30:00
Input
{{ article.published_at | date: "%Y" }}
Output
2015
date
works on strings if they contain well-formatted dates:
Input
{{ "March 14, 2016" | date: "%b %d, %y" }}
Output
Mar 14, 16
Timestamp StringsNote that LiquidJS is using JavaScript [Date][newDate] to parse the input string, that means IETF-compliant RFC 2822 timestamps and strings in a version of ISO8601 are supported.
To get the current time, pass the special word "now"
(or "today"
) to date
:
Input
This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.
Output
This page was last updated at 2020-03-25 15:57.
nowNote that the value will be the current time of when the page was last generated from the template, not when the page is presented to a user if caching or static site generation is involved.