File:lastModifiedDate 属性

备注: 此特性在 Web Worker 中可用。

已弃用: 不再推荐使用该特性。虽然一些浏览器仍然支持它,但也许已从相关的 web 标准中移除,也许正准备移除或出于兼容性而保留。请尽量不要使用该特性,并更新现有的代码;参见本页面底部的兼容性表格以指导你作出决定。请注意,该特性随时可能无法正常工作。

非标准: 该特性是非标准的,请尽量不要在生产环境中使用它!

File 接口的 lastModifiedDate 只读属性返回文件的最后修改日期。没有已知最后修改日期的文件则返回当前日期。

一个 Date 对象,指示上次修改文件的日期和时间。

示例

js
// fileInput 是一个 HTMLInputElement:<input type="file" multiple id="myfileinput">
const fileInput = document.getElementById("myfileinput");

for (const file of fileInput.files) {
  console.log(`${file.name} 最后修改日期为 ${file.lastModifiedDate}`);
}

时间精度降低

为了防止计时攻击和指纹识别someFile.lastModifiedDate 的精度可能会根据浏览器设置进行舍入。在 Firefox 中,privacy.reduceTimerPrecision 首选项默认启用,默认为 2ms。你还可以启用 privacy.resistFingerprinting,在这种情况下精度将为 100ms 或 privacy.resistFingerprinting.reduceTimerPrecision.microseconds 的值,以较大者为准。

例如,在降低时间精度的情况下,someFile.lastModifiedDate.getTime() 的结果将始终是 2 的倍数,或者在启用 privacy.resistFingerprinting 的情况下为 100 的倍数(或 privacy.resistFingerprinting.reduceTimerPrecision.microseconds)。

js
// Firefox 60 中的时间精度降低(2 毫秒)
someFile.lastModifiedDate.getTime();
// 可能是:
// 1519211809934
// 1519211810362
// 1519211811670
// …

// 启用 `privacy.resistFingerprinting` 会降低时间精度
someFile.lastModifiedDate.getTime();
// 可能是:
// 1519129853500
// 1519129858900
// 1519129864400
// …

规范

尽管存在于文件 API 规范的早期草案中,但此属性已从中删除,并且此属性现在是非标准的。使用 File.lastModified 代替。

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
lastModifiedDate
DeprecatedNon-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.

参见