Skip to main content

date

Date filter is used to convert a timestamp into the specified format.
  • LiquidJS tries to conform to Shopify/Liquid, which uses Ruby’s core Time###strftime(string). There’re differences with Ruby’s format flags:
  • %Z (since v10.11.1) is replaced by the passed-in timezone name from LiquidOption or in-place value (see TimeZone below). If passed-in timezone is an offset number instead of string, it’ll behave like %z. If there’s none passed-in timezone, it returns the runtime’s default time zone.
  • LiquidJS provides an additional %q flag for date ordinals. e.g. “ => 02nd of Feb
  • Date literals are firstly converted to Date object via new Date(), that means literal values are considered in runtime’s time zone by default.
  • The format filter argument is optional:
  • If not provided, it defaults to %A, %B %-e, %Y at %-l:%M %P %z.
  • The above default can be overridden by dateFormat LiquidJS option.
  • LiquidJS date supports locale specific weekdays and month names, which will fallback to English where Intl is not supported.
  • Ordinals (%q) and Jekyll specific date filters are English-only.
  • locale can be set when creating Liquid instance. Defaults to Intl.DateTimeFormat().resolvedOptions.locale).

Examples

TimeZone

  • During output, LiquidJS uses local timezone which can override by:
  • setting a timezone in-place when calling date filter, or
  • setting the timezoneOffset LiquidJS option
  • It defaults to runtime’s time one.
  • Offset can be set as,
  • minutes: -360 means '+06:00' and 360 means '-06:00'
  • timeZone ID: Asia/Colombo or America/New_York
  • See here for TZ database values

Examples

Input

Examples

Current Date

  • To get the current time, pass the special word "now" or "today" as input
  • Note 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

Example

date_to_string

Convert a date to short format. Same with Jekyll date_to_string filter.
Note that JavaScript Date has not timezone information, see date filter for details.

date_to_long_string

Convert a date to long format. Same with Jekyll date_to_long_string filter.
Note that JavaScript Date has not timezone information, see date filter for details.

date_to_xmlschema

Convert a Date into XML Schema (ISO 8601) format, same as Jekyll filter date_to_xmlschema.
Note that JavaScript Date has not timezone information, see date filter for details.

date_to_rfc822

Convert a Date into the RFC-822 format used for RSS feeds, same as Jekyll filter date_to_rfc822.
Note that JavaScript Date has not timezone information, see date filter for details.