My question is : why when I use "document.lastModified" on my web page, it returns me the current date and time, not the time when this page was last Modified... Any ideas? Thanks in advance :)
Actual code is :
<script type="text/javascript"> document.write("Page was last modified on: " + document.lastModified);</script>
The File. lastModified read-only property provides the last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
The lastModified property of the Document interface returns a string containing the date and time on which the current document was last modified.
The DOM lastModified property in HTML is used to return the date and time of the current document that was last modified. This property is read-only. This property returns a string which contains the date and time when the document was last modified.
javascript:alert(document.lastModified) A JavaScript alert window will pop open displaying the last date and time the page was modified. For users of the Chrome browser and some others, if you cut-and-paste the command into the address bar, be aware that the "javascript:" part is removed.
I conducted an experiment today. I put the following script on my server in a file touched to be last modified on 1 Jan:
var theDate = new Date(document.lastModified).toISOString().substr(5, 5).replace('-', '');
document.write(theDate);
and asked visitors to tell me what they see. 103 said they see "0101", the expected string, 8 said they see "0308", ie the current date. All the bad answers came from Android, Chrome/7[12] users. Good answers (22) also came from other Android users, typically with earlier versions of Chrome. However there were 10 Android Chrome/72 users who saw the good date.
Based on this small sample, there must be something wrong in Android Chrome versions 71+, but it is stochastic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With