JavaScript Document lastModified Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

Document.lastModified returns a string with the date and local time when the current document was last modified (MDN).

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use document.lastModified. Start with this line.

JavaScript
document.lastModified
CallWhat it does
document.lastModifiedPrimary signature.

Built into the browser. Read or assign document.lastModified — no import required.

Library declarations
JavaScript
document.lastModified

Parameters

ParameterDescription
lastModifiedRequired. Human-readable date/time string
Cookie / storageOptional. Remember a previous visit timestamp

Return Value

Return ValueDescription
*The current value of document.lastModified.

JavaScript Examples

Example 1 — Log document.lastModified

Print the last-modified date/time string for the current document (MDN pattern).

JavaScript
console.log(document.lastModified);
// e.g. "12/16/2017, 11:09:42" (format varies by browser/locale)
Try It Yourself

How It Works

  1. Read the property. No arguments—access document.lastModified.
  2. Get a string. It describes the last-modified date and local time.
  3. Format can vary. Do not hard-code one locale layout when parsing by hand.
  4. Good for display. Fine to show as-is in a footer; parse before comparing.

Example 2 — Convert to a Date

Turn the string into a Date object so you can call date methods (MDN).

JavaScript
const lastMod = new Date(document.lastModified);

console.log(lastMod.toString());
console.log(Number.isNaN(lastMod.getTime())); // false if parse succeeded
Try It Yourself

How It Works

  1. Pass the string to Date. new Date(document.lastModified) builds a Date.
  2. Use Date methods. Format, get year/month, or convert to ISO.
  3. Validate parse. getTime() is NaN if the string could not be parsed.
  4. Still one document. This reflects the current page’s last-modified time only.

Example 3 — Convert to Milliseconds

Get a numeric timestamp for easy comparison and storage (MDN).

JavaScript
const ms = Date.parse(document.lastModified);

console.log(ms);
console.log(typeof ms); // "number"
Try It Yourself

How It Works

  1. Parse the string. Date.parse returns milliseconds since the Unix epoch.
  2. Compare numbers. Use > / < on ms, not on the raw string.
  3. Store easily. Cookies or localStorage can keep a numeric timestamp.
  4. Invalid parse. Failed parses yield NaN—check before comparing.

Browser Support

Document.lastModified is Baseline Widely available on MDN (since July 2015). It works across modern browsers and long-supported evergreen releases.

✓ Baseline · Widely available

Document.lastModified

Read-only date/time string for when the current document was last modified — parse with Date for comparisons.

99% Browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · Modern WebView
Full support
lastModified Excellent

Bottom line: Safe everywhere you teach DOM APIs. Display the string freely; always parse before comparing. For external pages, prefer HEAD + Last-Modified.

Frequently Asked Questions

A string containing the date and local time when the current document was last modified (MDN).
No. MDN marks Document.lastModified as Baseline Widely available (since July 2015). It is a standard Document property.
Do not compare the strings directly. Convert with Date.parse(document.lastModified) or new Date(document.lastModified), then compare numbers or Date objects (MDN).
MDN shows storing a timestamp in a cookie and comparing it to Date.parse(document.lastModified) on later visits.
MDN suggests a HEAD request with fetch() and reading the Last-Modified response header.
No useful assignment — treat it as a read-only report of the document's last-modified time from the browser.

Next: lastStyleSheetSet

Learn the legacy last selected style sheet set property.

lastStyleSheetSet tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful