Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lastModified() function returns current date and time

Tags:

javascript

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>
like image 227
Eddi994 Avatar asked Apr 15 '13 20:04

Eddi994


People also ask

What is lastModified?

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.

What does document lastModified contain?

The lastModified property of the Document interface returns a string containing the date and time on which the current document was last modified.

How do I show the last modified date in HTML?

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.

How do I use lastModified alert document?

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.


1 Answers

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.

like image 110
szigetva Avatar answered Oct 22 '22 14:10

szigetva