Document.lastModified

  • Revision slug: DOM/document.lastModified
  • Revision title: document.lastModified
  • Revision id: 370303
  • Created:
  • Creator: fusionchess
  • Is current revision? No
  • Comment

Revision Content

{{DomRef}}

Summary

Returns a string containing the date and time on which the current document was last modified.

Syntax

string = document.lastModified; 

Example

alert(document.lastModified); 
// returns: Tuesday, July 10, 2001 10:19:42

Notes

Note that as a string, lastModified cannot easily be used for comparisons between the modified dates of documents. Here is a possible example:

if (Date.parse(document.lastModified) > parseFloat(document.cookie.replace(/(?:(?:^|.*;\s*)last_modif\s*\=\s*((?:[^;](?!;))*[^;]?).*)|.*/, "$1") || "0")) {
    document.cookie = "last_modif=" + Date.now() + "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=" + location.pathname;
    alert("This page has changed!");
}
Note: WebKit returns the time string in UTC; Gecko and Internet Explorer return a time in the local timezone.
(See: Bug 4363 – document.lastModified returns date in UTC time, but should return it in local time)

Specification

{{DOM0}}

See also

  • {{MSDN("ms533946", "lastModified Property")}}

Revision Source

<div>
  {{DomRef}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>Returns a string containing the date and time on which the current document was last modified.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<var>string</var> = document.lastModified; 
</pre>
<h2 id="Example" name="Example">Example</h2>
<pre class="brush:js">
alert(document.lastModified); 
// returns: Tuesday, July 10, 2001 10:19:42
</pre>
<h2 id="Notes" name="Notes">Notes</h2>
<p>Note that as a string, <code>lastModified</code> cannot easily be used for comparisons between the modified dates of documents. Here is a possible example:</p>
<pre class="brush: js">
if (Date.parse(document.lastModified) &gt; parseFloat(document.cookie.replace(/(?:(?:^|.*;\s*)last_modif\s*\=\s*((?:[^;](?!;))*[^;]?).*)|.*/, "$1") || "0")) {
&nbsp;&nbsp; &nbsp;document.cookie = "last_modif=" + Date.now() + "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=" + location.pathname;
&nbsp;&nbsp; &nbsp;alert("This page has changed!");
}</pre>
<div class="note">
  <strong>Note:</strong> WebKit returns the time string in UTC; Gecko and Internet Explorer return a time in the local timezone.<br />
  (See: <a href="https://bugs.webkit.org/show_bug.cgi?id=4363" title="Bug 4363 – document.lastModified returns date in UTC time, but should return it in local time">Bug 4363 – document.lastModified returns date in UTC time, but should return it in local time</a>)</div>
<h2 id="Specification" name="Specification">Specification</h2>
<p>{{DOM0}}</p>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{MSDN("ms533946", "lastModified Property")}}</li>
</ul>
Revert to this revision