- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - datetime Attribute
HTML datetime attribute is used to indicate the date and time associated with the element.
It is used to specify the date and time when the text has been inserted or deleted. The value of the datetime attribute must be in a valid format with an optional time string. If the value can't be parsed as a date with an optional time string, the element is not having an associated timestamp.
Syntax
<tag datetime = "value"></tag>
Where value can be any date and time as the following format −
Year-month-day or 2023-07-11 or 2023-07-11T15:17:00
Applies On
Below listed elements allow using of the HTML datetime attribute
Element | Description |
---|---|
<del> | HTML <del> tag is use to mark the deleted textual content on the website. |
<ins> | HTML <ins> tag represents a range of text that has been inserted into an HTML document. |
<time> | HTML <time> tag is used to define a specific date and time. |
Examples of HTML datetime attribute
Bellow examples will illustrate the HTML datetime attribute, where and how we should use this attribute!
Define deleted element datetime
In the following example, we are using the HTML ‘datetime’ attribute within the <del> tag to indicate the date and time associated with this element.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'datetime' attribute</title> </head> <body> <!--HTML 'datetime' attribute--> <p>Example of the HTML 'datetime' attribute</p> <del datetime="2023-07-11T14:26:00"> Text within the 'del' tag has been deleted. </del> </body> </html>
Define inserted element datetime
Considering the another scenario, where we are going to use the datetime attribute along with the ins tag.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'datetime' attribute</title> </head> <body> <!--HTML 'datetime' attribute--> <p>Example of the HTML 'datetime' attribute</p> <ins datetime="2023-07-11T14:42:04"> Text inserted within the 'ins' element. </ins> </body> </html>
Datetime attribute with time tag
Let's look at the following example, where we are going to use the datetime attribute along with the time tag and use javascript to print current time. This is used for machin readable.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'datetime' attribute</title> </head> <body> <!--HTML 'datetime' attribute--> <p>Example of the HTML 'datetime' attribute</p> <h3>HTML 'datetime' attribute with 'time' element</h3> <p>The concert is on <time datetime="2023-07-15T15:02:00"> 15 July</time> </p> <p>Current time is: <time datetime="2023-07-11T15:03:00" id='demo'></time> </p> <script> var d = new Date(); var h = d.getHours(); var m = d.getMinutes(); var s = d.getSeconds(); var res = document.getElementById('demo'); res.innerHTML = h + " : " + m + " : " + s; </script> </body> </html>
Supported Browsers
Attribute | |||||
---|---|---|---|---|---|
datetime | Yes 62.0 | Yes 18.0 | Yes 22.0 | Yes 7.0 | Yes 49.0 |
To Continue Learning Please Login
Login with Google