HTML | DOM Time Object
The DOM Time Object is used to represent the HTML Time element . The Time element is accessed by getElementById().
Properties:
- dateTime: It contains single attribute datetime which is used to set or return the date/time in a machine-readable form of the element.
Syntax:
document.getElementById("ID");
Where “id” is the ID assigned to the “time” tag.
Example-1:
<!DOCTYPE html> < html > < head > < title >DOM Time Object</ title > < style > body { text-align: center; } h1 { color: green; } </ style > </ head > < body > < h1 >GeeksForGeeks</ h1 > < h2 >DOM Time Object</ h2 > Jawahar lal Nehru birthday is celebrated on <!-- Assigning id to time tag. --> < time Id = "GFG" datetime = "2018--11-14 12:00" > children's day. </ time > < br > < br > < button onclick = "myGeeks()" >Submit</ button > < p id = "sudo" ></ p > < script > function myGeeks() { var g = document.getElementById("GFG").innerHTML; document.getElementById("sudo").innerHTML = g; } </ script > </ body > </ html > |
Output:
Before Clicking On Button:
After Clicking On Button:
Example-2: <Time> Object can be created by using the document.createElement method.
<!DOCTYPE html> < html > < head > < title >DOM Time Object</ title > < style > body { text-align: center; } h1 { color: green; } </ style > </ head > < body > < h1 >GeeksForGeeks</ h1 > < h2 >DOM Time Object</ h2 > < br > < button onclick = "myGeeks()" >Submit</ button > < script > function myGeeks() { // time tag created var g = document.createElement("TIME"); g.setAttribute( "datetime", "2018--11-14 12:00"); var f = document.createTextNode("Children's day"); g.appendChild(f); document.body.appendChild(g); } </ script > </ body > </ html > |
Output :
Before Clicking On Button:
After Clicking On Button :
Supported Browsers: The browser supported by DOM Time Object are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM Input Time Object
- HTML | DOM Object Object
- HTML DOM Aside Object
- HTML | DOM dl Object
- HTML | DOM DT Object
- HTML | DOM li Object
- HTML| DOM Ins Object
- HTML | DOM Bdo Object
- HTML | DOM DFN Object
- HTML | DOM DD Object
- HTML | DOM Del Object
- HTML | DOM S Object
- HTML | DOM Kbd Object
- HTML | DOM Nav Object
- HTML| DOM HR Object
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.