Document.lastModified is an instance property that returns a string with the date and local time when the current document was last modified. Learn how to display it, convert it to a Date, compare timestamps, and five examples with try-it labs.
01
Kind
Instance property
02
Returns
string
03
Means
Last modified
04
Parse
Date / Date.parse
05
Compare
Use numbers
06
Status
Baseline widely
Fundamentals
Introduction
Want to show visitors when a page was updated? document.lastModified gives you that information as a readable date/time string in the user’s local time zone.
MDN: the property returns a string containing the date and local time on which the current document was last modified. The value often comes from the server’s Last-Modified information (or a fallback the browser provides).
💡
Compare with numbers, not strings
MDN notes that as a string, lastModified is hard to compare directly. Convert with Date.parse() or new Date() before sorting or checking for updates.
Document.lastModified is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.lastModified
String with the date and local time when the current document was last modified.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in legacy IE
Full support
Document.lastModifiedExcellent
Bottom line: Display document.lastModified for an Updated line, or parse with Date / Date.parse before comparing timestamps.
Wrap Up
Conclusion
Document.lastModified is a simple way to read when the current page was last modified. Display the string, or parse it into a Date / milliseconds when you need comparisons, cookies, or locale-friendly formatting.
Use toLocaleString for visitor-friendly Updated labels
Store visit timestamps in cookies carefully (path / expiry)
Use HEAD + Last-Modified for external pages (MDN)
Handle NaN if parsing fails
❌ Don’t
Compare raw lastModified strings with > / <
Assume every browser formats the string identically
Treat it as a precise “content publish date” for SEO without verifying the server
Forget that local files / try-it sandboxes may report unexpected times
Rely on cookies alone if users block them
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.lastModified
When this document was last modified — as a string.
5
Core concepts
📄01
Returns
string
API
📅02
Means
Last modified
Local time
🕐03
Parse
Date / parse
MDN
⚖️04
Compare
Use ms
Not strings
🌐05
External
HEAD header
fetch
❓ Frequently Asked Questions
A string with 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.
Browsers return a human-readable date/time string in local time. Always parse it with Date APIs before sorting or comparing.
Did you know?
Opening a page from disk (file://) or from a live editor sandbox can produce different lastModified values than a production URL—always verify on the real server when freshness matters.