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.getTime() 的精度可能会根据浏览器设置进行舍入。

在 Firefox 中,privacy.reduceTimerPrecision 首选项默认启用,在 Firefox 59 中默认为 20 微秒;Firefox 60 中为 2 毫秒。

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

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

在 Firefox 中,你还可以启用 privacy.resistFingerprinting,精度将为 100 毫秒或 privacy.resistFingerprinting.reduceTimerPrecision.microseconds 的值,以较大者为准。

规范

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

浏览器兼容性

BCD tables only load in the browser

参见