How to display the date and time of a document when it is last modified in JavaScript?


A document in its lifetime will undergo many changes. Javascript has provided a command called document.lastModified to get the instance when the document is last modified. This command will provide the exact date and time of modification.  

syntax

Time = document.lastModified;

Example-1

In the following example, using the document.lastModified method the documents last modification date and time are displayed as shown in the output.

Live Demo

<html>
<body>
<script>
   document.write("This document is lastly modified on" + " " +document.lastModified);
</script>
</body>
</html>

Output

This document is lastly modified on 07/29/2019 15:19:41


Example-2

In the following example, using the document.lastModified method the documents last modification date and time are displayed as shown in the output. When I modified the document the date and time are 07/29/2019 15:26:23.

Live Demo

<html>
<body>
<p>This document was last modified <span id="modify"></span>.</p>
<script>
   document.getElementById("modify").innerHTML = document.lastModified
</script>
</body>
</html>

Output

This document was last modified 07/29/2019 15:26:23.
raja
Published on 29-Jul-2019 15:33:21
Advertisements