Time dateTime Attribute

Definition and Usage

dateTime Sets or returns the value of the datetime attribute of the <time> element.

<time> datetime attribute Provide the specified date or time. If the content of the element does not specify a date or time, use this attribute.

Note:The datetime attribute will not be displayed as any special effect in any mainstream browser.

See also:

HTML Reference Manual:HTML <time> Tag

Example

Example 1

Get the date represented by the <time> element:

var x = document.getElementById("myTime").dateTime;

Try It Yourself

Example 2

Change the date and time of the <time> element:

document.getElementById("myTime").dateTime = "2023-08-22T18:00Z";

Try It Yourself

Syntax

Return dateTime attribute:

timeObject.dateTime

Set dateTime attribute:

timeObject.dateTime = YYYY-MM-DDThh:mm:ssTZD

Attribute Value

Value Description
YYYY-MM-DDThh:mm:ssTZD

Specified date or time.

Component Description:

  • YYYY - Year (for example, 2022)
  • MM - Month (for example, 06 represents January)
  • DD - Day of the month (for example, 18)
  • T - Required separator
  • hh - Hour (for example, 22 represents 10 PM)
  • mm - Minutes (e.g., 55)
  • ss - Seconds (e.g., 03)
  • TZD - Time Zone Indicator (Z represents Zulu, also known as Greenwich Mean Time)

Technical Details

Return Value: A string value representing the machine-readable form of the element's date and time.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Not Supported Not Supported Supported Not Supported Not Supported

Related Pages

HTML Reference Manual:HTML <time> datetime Attribute