The datetime
attribute sets the date or time
if no date or time is specified in the element's content.
The dateTime
property sets or gets
the datetime attribute in a <time> element.
dateTime |
No | No | Yes | No | Yes |
Return the dateTime property.
var v = timeObject.dateTime
Set the dateTime property.
timeObject.dateTime=YYYY-MM-DDThh:mm:ssTZD
Value | Description |
---|---|
YYYY-MM-DDThh:mm:ssTZD | The date or time being specified.
|
A String type value 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.
<!DOCTYPE html>
<html>
<body>
<time id="myTime" datetime="2014-02-28">a day</time>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from w ww . java 2 s . c o m-->
var x = document.getElementById("myTime").dateTime;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the date and time of a <time> element.
<!DOCTYPE html>
<html>
<body>
<time id="myTime" datetime="2014-02-28T08:00Z">my day</time>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from ww w .j a v a 2 s . co m-->
document.getElementById("myTime").dateTime = "2014-06-24T09:30Z";
}
</script>
</body>
</html>
The code above is rendered as follows: