time_ tag
Converts a timestamp into an HTML <time> tag.
The 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.
Code
{{ article.created_at | time_tag: '%B %d, %Y' }}Data
{
"article": {
"created_at": "2022-04-14 16:56:02 -0400"
}
}Output
Output
<time datetime="2022-04-14T20:56:02Z">April 14, 2022</time>format
Specify a locale-aware date format. Accepts the following values:
basicdatedefaultshort(deprecated)long(deprecated)
You can also define custom formats in your theme's locale files.
You can also define custom formats in your theme's locale files.
Note: You can also <a href="/docs/api/liquid/filters/date-setting-format-options-in-locale-files">define custom formats</a> in your theme's locale files.
Code
{{ article.created_at | time_tag: format: 'abbreviated_date' }}Data
{
"article": {
"created_at": "2022-04-14 16:56:02 -0400"
}
}Output
Output
<time datetime="2022-04-14T20:56:02Z">Apr 14, 2022</time>datetime
By default, the value of the datetime attribute of the <time> tag is formatted as . However, you can specify a custom format with strftime shorthand formats.
Code
{{ article.created_at | time_tag: '%B %d, %Y', datetime: '%Y-%m-%d' }}Data
{
"article": {
"created_at": "2022-04-14 16:56:02 -0400"
}
}Output
Output
<time datetime="2022-04-14">April 14, 2022</time>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 category:
"date_formats": {
"month_day_year": "%B %d, %Y"
}Code
{{ article.created_at | time_tag: format: 'month_day_year' }}Data
{
"article": {
"created_at": "2022-04-14 16:56:02 -0400"
}
}Output
Output
<time datetime="2022-04-14T20:56:02Z">April 14, 2022</time>