W3cubDocs

/DOM

File.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.

Syntax

var time = instanceOfFile.lastModified;

Value

A number that represents the number of milliseconds since the Unix epoch.

Example

Reading from file input

<input type="file" multiple id="fileInput">
const fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', function(event) {
  // files is a FileList object (simliar to NodeList) 
  const files = event.target.files;

  for (let i = 0; i < files.length; i++) {
    const date = new Date(files[i].lastModified);
    alert(files[i].name + ' has a last modified date of ' + date);
  }
});

Try the results out below:

Dynamically created files

If a File is created dynamically, the last modified time can be supplied in the new File() constructor function. If it is missing, lastModified inherits the current time from Date.now() at the moment the File object gets created.

var fileWithDate = new File([], 'file.bin', {
  lastModified: new Date(2017, 1, 1),
});
console.log(fileWithDate.lastModified); //returns 1485903600000

var fileWithoutDate = new File([], 'file.bin');
console.log(fileWithoutDate.lastModified); //returns current time

Specifications

Specification Status Comment
File API
The definition of 'lastModified' in that specification.
Working Draft Initial definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
File.lastModified 13.0 (Yes) 15.0 (15.0) 10.0 16.0 No support
Feature Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
File.lastModified No support (Yes) No support No support No support No support

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/File/lastModified