You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/filters/date.md
+14-17
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,15 @@ title: date
3
3
---
4
4
{% since %}v1.9.1{% endsince %}
5
5
6
-
# Format
7
-
* Converts a timestamp into another date format
8
-
* LiquidJS tries to be conformant with Shopify/Liquid which is using Ruby's core [Time#strftime(string)](http://www.ruby-doc.org/core/Time.html#method-i-strftime)
*Not all options are supported though - refer [differences here](/tutorials/differences.html#Differences)
11
-
*The input is firstly converted to `Date` object via [new Date()][jsDate]
12
-
*Date format can be provided individually as a filter option
13
-
* If not provided, then `%A, %B %-e, %Y at %-l:%M %P %z` format will be used as default format
14
-
*Override this using [`dateFormat`](/api/interfaces/LiquidOptions.html#dateFormat) LiquidJS option, to set your preferred default format for all date filters
6
+
Date filter is used to convert a timestamp into the specified format.
7
+
8
+
* LiquidJS tries to conform to Shopify/Liquid, which uses Ruby's core [Time#strftime(string)](http://www.ruby-doc.org/core/Time.html#method-i-strftime). There're differences with [Ruby's format flags](https://ruby-doc.org/core/strftime_formatting_rdoc.html):
9
+
*`%Z` (since v10.11.1) works when there's a 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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions#timezone).
10
+
*LiquidJS provides an additional `%q` flag for date ordinals. e.g. `{{ '2023/02/02' | date: '%d%q of %b'}}` => `02nd of Feb`
11
+
*Date literals are firstly converted to `Date` object via [new Date()][jsDate], that means literal values are considered in runtime's time zone by default.
12
+
*The format filter argument is optional:
13
+
* If not provided, it defaults to `%A, %B %-e, %Y at %-l:%M %P %z`.
14
+
*The above default can be overridden by [`dateFormat`](/api/interfaces/LiquidOptions.html#dateFormat) LiquidJS option.
15
15
16
16
### Examples
17
17
```liquid
@@ -23,16 +23,14 @@ title: date
23
23
```
24
24
25
25
# TimeZone
26
-
* By default, dates will be converted to local timezone before output
27
-
* You can override that by,
28
-
* setting a timezone for each individual `date` filter via the second parameter
29
-
* using the [`timezoneOffset`](/api/interfaces/LiquidOptions.html#timezoneOffset) LiquidJS option
30
-
* Its default value is your local timezone offset which can be obtained by `new Date().getTimezoneOffset()`
26
+
* During output, LiquidJS uses local timezone which can override by:
27
+
* setting a timezone in-place when calling `date` filter, or
28
+
* setting the [`timezoneOffset`](/api/interfaces/LiquidOptions.html#timezoneOffset) LiquidJS option
29
+
* It defaults to runtime's time one.
31
30
* Offset can be set as,
32
31
* minutes: `-360` means `'+06:00'` and `360` means `'-06:00'`
33
32
* timeZone ID: `Asia/Colombo` or `America/New_York`
34
-
* Use minutes for better performance with repeated processing of templates with many dates like, converting template for each email recipient
35
-
* Refer [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) for TZ database values
33
+
* See [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) for TZ database values
*`date` works on strings if they contain well-formatted dates
47
44
* Note that LiquidJS is using [JavaScript Date][jsDate] to parse the input string, that means [IETF-compliant RFC 2822 timestamps](https://datatracker.ietf.org/doc/html/rfc2822#page-14) and strings in [a version of ISO8601](https://www.ecma-international.org/ecma-262/11.0/#sec-date.parse) are supported.
0 commit comments