Skip to main content

time_tag

string | time_tag: string
returns string

Converts a timestamp into an HTML <time> tag.

The time_tag filter accepts the same parameters as Ruby's strftime method for formatting the date. For a list of shorthand formats, refer to the Ruby documentation or strftime reference and sandbox.

{{ article.created_at | time_tag: '%B %d, %Y' }}

Output

<time datetime="2022-04-14T20:56:02Z">April 14, 2022</time>
string | time_tag: format: string

Specify a locale-aware date format. Accepts the following values:

  • abbreviated_date
  • basic
  • date
  • date_at_time
  • default
  • on_date
  • short (deprecated)
  • long (deprecated)

Note

You can also define custom formats in your theme's locale files.


{{ article.created_at | time_tag: format: 'abbreviated_date' }}

Output

<time datetime="2022-04-14T20:56:02Z">Apr 14, 2022</time>
string | time_tag: datetime: string

By default, the value of the datetime attribute of the <time> tag is formatted as YYYY-MM-DDThh:mm:ssTZD. However, you can specify a custom format with strftime shorthand formats.

{{ article.created_at | time_tag: '%B %d, %Y', datetime: '%Y-%m-%d' }}

Output

<time datetime="2022-04-14">April 14, 2022</time>
Anchor to Setting format options in locale files

Setting format options in locale files

You can define custom date formats in your theme's storefront locale files. These custom formats should be included in a date_formats category:

"date_formats": {
"month_day_year": "%B %d, %Y"
}
{{ article.created_at | time_tag: format: 'month_day_year' }}

Output

<time datetime="2022-04-14T20:56:02Z">April 14, 2022</time>
Was this page helpful?