ActionView::Helpers::DateHelper
def time_tag(date_or_time, content = nil, options = {}, &block)

Description

Creates a <time> element for a date or a date and time.

Arguments

Changing a value updates the ERB and HTML.

Sets the datetime attribute to this value in iso8601 format. If the content argument is omitted, the localized date or time becomes the content. Passing anything other than a Date, DateTime or Time raises I18n::ArgumentError (NoMethodError if the content argument is given).
= nil
The content of the <time>, escaped. Defaults to the date_or_time argument localized with I18n.l.
options= {}
The format for building the content when the content argument is omitted (ignored when content is given). Accepts:
  • A symbol: looks up the key with this name in the date.formats or time.formats translation and passes its value to strftime (for :short, the value of date.formats.short). A name that is not in the translations raises I18n::MissingTranslationData (even with a block).
  • A string ("%B %Y"): used as a strftime format.
This site's Japanese translations are the same as rails-i18n, and the English ones are Rails' own.
"2026-W46"
Overrides the datetime attribute built from the date_or_time argument. The content is unchanged.
Common options

Rails handles these options the same way in every helper. Options the HTML spec does not allow on the <time>, and ones this site considers rarely used, are not listed here.

Shared by all helpers

true adds disabled="disabled"; false omits it. The same goes for every HTML attribute in Rails' list (BOOLEAN_ATTRIBUTES), such as readonly, required and autofocus: any value other than false or nil adds it as attr="attr".
{active: true, hidden: false}
A hash gives the keys whose values are not false or nil, joined with spaces. An array gives its elements joined with spaces, after removing nil, false and empty strings (including whitespace-only strings).
{controller: "tags", tags_suggestions_value: ["ruby", "rails"]}
A hash adds data-* attributes, with _ in the keys converted to -. Array and hash values are converted to JSON strings.
{describedby: ["name_help", "name_error"], invalid: false}
Like :data, adds aria-* attributes. Array values are joined with spaces, leaving out nil and empty strings (nothing is added if none remain). For a hash value, the keys whose values are not false or nil are joined with spaces.
["section-user", "name"]
An array sets autocomplete to its elements joined with spaces.
/[a-z]+/i
A regular expression sets pattern to the part between / and /. Flags such as i are not included.
Any other options become HTML attributes of the <time>; those with a nil value are left out.
&block= nil
With a block, uses the block's output as the content and ignores the content argument if it is also given.

ERB

Changes from the previous output: Added Removed Changed


          

HTML


          

Preview