HTML - DOM Document lastModified Property
HTML DOM document lastModified property returns the date and time of the current document when it was last modified.
Syntax
document.lastModified;
Return Value
It returns String representing the date and time the document was last modified.
Examples of HTML DOM Document 'lastModified' Property
Given below are some examples of lastModified property.
Get the Date and Time
The following example returns the date and time when the document was last modified.
<!DOCTYPE html>
<html lang="en">
<head>
<title>
HTML DOM document lastModified Property
</title>
</head>
<body>
<p>Welcome to Tutorials Point.</p>
<button onclick="fun()">Click me</button>
<p id="lastmod"></p>
<script>
function fun() {
let x = document.lastModified;
document.getElementById("lastmod").innerHTML =
"This document was last modified on :" + x;
}
</script>
</body>
</html>
Convert lastModified property into a Date Object
The following example returns the date and time into a date object.
<!DOCTYPE html>
<html lang="en">
<head>
<title>
HTML DOM document lastModified Property
</title>
</head>
<body>
<p>Welcome to Tutorials Point.</p>
<button onclick="fun()">Click me</button>
<p id="lastmod"></p>
<script>
function fun() {
const x = new Date(document.lastModified);
document.getElementById("lastmod").innerHTML = x;
}
</script>
</body>
</html>
Supported Browsers
| Property | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| lastModified | Yes 1 | Yes 12 | Yes 1 | Yes 1 | Yes 12.1 |
html_dom.htm
Advertisements




