Time dateTime Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Time

Description

The dateTime property sets or gets the datetime attribute in a <time> element.

Set the dateTime property with the following Values

Value Description
YYYY-MM-DDThh:mm:ssTZD The date or time being specified.
  • YYYY - year (e.g. 2009)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 08)
  • T - a required separator
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 55)
  • ss - seconds (e.g. 03)
  • TZD - Time Zone Designator (Z as Greenwich Mean Time)

Return Value

A String, representing a machine-readable form of the element's date and time

The following code shows how to get the date that a <time> element represents:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from   w  w  w .  j  a  va 2 s.c  o  m
    var v = document.getElementById("myTime").dateTime;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials