Javascript Reference - HTML DOM ins dateTime Property








The datetime attribute specifies when the text was inserted.

The dateTime property sets or gets the value of the datetime attribute.

Browser Support

The dateTime property is supported in all major browsers.

dateTime Yes Yes Yes Yes Yes

Syntax

Return the dateTime property.

var v = insObject.dateTime 

Set the dateTime property.

insObject.dateTime=YYYY-MM-DDThh:mm:ssTZD

Property Values

Value Description
YYYY-MM-DDThh:mm:ssTZD Specifies when the text was inserted.
  • YYYY - year (e.g. 2014)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 05)
  • T - a required separator
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 51)
  • ss - seconds (e.g. 07)
  • TZD - Time Zone Designator




Return Value

A String type value representing of when the text was inserted.

Example

The following code shows how to change the datetime attribute.


<!DOCTYPE html>
<html>
<body>
<ins id="myIns" datetime="2014-04-14T24:54:04Z">This is an inserted text.</ins>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<!--   w w  w  .j a v a 2  s. co  m-->
<script>
function myFunction() {
    document.getElementById("myIns").dateTime = "2014-10-10T20:40:07Z";
    document.getElementById("demo").innerHTML = "changed";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get when the text was inserted.


<!DOCTYPE html>
<html>
<body>
<ins id="myIns" datetime="2014-02-15T12:56:03Z">This is an inserted text.</ins>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--  w  ww .  ja  v a  2 s .  co  m-->
    var x = document.getElementById("myIns").dateTime;
    document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

The code above is rendered as follows: