Chengzhi Chengzhi - 2 months ago 7
HTML Question

How to see the last modified HTML date by JavaScript


I have an issue with JavaScript to show the last modified date of .html file.
I tried to put the last modified date code in my footer, thus I do not need to write those code anymore. And it will show the last modified date of each page.

I tried the code on the website:

<title>Last Modified</title>
<meta http-equiv="Content-Type" content="text/html;
<script type="text/javascript">

function showLastModified() {
var out = document.getElementById('lastModified');
var d = new Date();
if (d.toLocaleDateString) {
out.innerHTML = d.toLocaleDateString(document.lastModified);
else {
out.innerHTML = document.lastModified;

window.onload = showLastModified;
Last Modified on <span id="lastModified">&nbsp;</span>

However, it still show the date of today. I think it is because of d.toLocaleDateString, but I can not figure out. Can anyone help me resolve my problem.


Most browsers support document.lastModified. but you need to turn the string into a Date object before calling toLocaleString-

    new Date(document.lastModified).toLocaleString();