HTML datetime Attribute: The HTML datetime attribute used to define the machine-readable date/time of the <time> element. The date-time is inserted in the format YYYY-MM-DDThh:mm:ssTZD.
Attribute Values: This attribute contains single value YYYY-MM-DDThh:mm:ssTZD which is used to specify the date and time when the text was deleted.
HTML datetime Attribute
This attribute can be applied to the elements like <del>,<ins>,<time>.
Syntax: <time datetime=”YYYY-MM-DDThh:mm:ssTZD”>
The explanation of datetime components are listed below:
YYYY: It sets the year of datetime object (e.g. 2018).
MM: It sets the month of datetime object (e.g. 04 for March).
DD: It sets the day of the month of datetime object (e.g. 06).
T: It is a required separator.
hh: It sets the hour of datetime object (e.g. 18 for 06.00pm).
mm: It sets the minutes of datetime object (e.g. 34).
ss: It sets the seconds of datetime object (e.g. 40).
TZD: Time Zone Designator (Z denotes Zulu, also known as Greenwich Mean Time)
Browser Support
This attribute is supported by the following browsers :
- Chrome
- Firefox
- Safari
- Opera
- Internet Explorer
<del> element Example
<!DOCTYPE html> <html> <body> <p><del datetime="2015-11-15T22:55:03Z">The current text is deleted</del></p> </body> </html>
Output:
<ins> element Example
Example for <ins> element <!DOCTYPE html> <html> <body> <ins datetime="2015-09-15T22:55:03Z">The current text is an inserted text.</ins> </body> </html>
Output:
Example:<time> element
<!DOCTYPE html> <html> <body> <p>I have a birthday invitation from <time datetime="2017-07-15 20:00">Karthik </time>.</p> <p><b>Note:</b> The time element does not render as anything special in any of the major browsers.</p> <p><strong>Note:</strong> The time tag is not supported in Internet Explorer 8 and earlier versions.</p> </body> </html>
Output: