HTML DOM Time Object


The HTML DOM Time Object in HTML represents the <time> element.

Creating a <time> element

var timeObject = document.createElement(“TIME”)

Here, “timeObject” can have the following properties −

Property
Description
dateTime
Itsets/returns the value of the dateTime attribute of a <time>element

Let us see an example of Time dateTime property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Time dateTime</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
   <form>
      <fieldset>
         <legend>Time-dateTime</legend>
         <label>Notification : <strong>Examination Incoming!</strong>
         <time id="TimeDateTimeSelect" dateTime="2019-05-23T12:45Z">
         </label>
         <input type="button" onclick="getExamDate()" value="What's the Exam Date?">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var TimeDateTimeSelect = document.getElementById("TimeDateTimeSelect");
   function getExamDate() {
      divDisplay.textContent = 'Examination Date: '+TimeDateTimeSelect.dateTime;
   }
</script>
</body>
</html>

Output

Before clicking ‘What’s the Exam Date?’ button −

After clicking ‘What’s the Exam Date?’ button −

Updated on: 29-Oct-2019

121 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements