檔案:lastModifiedDate 屬性
注意:此功能在 Web Workers 中可用。
已棄用:此特性不再推薦。雖然某些瀏覽器可能仍然支援它,但它可能已經從相關的網路標準中刪除,可能正在刪除過程中,或者可能僅為相容性目的而保留。請避免使用它,如果可能,請更新現有程式碼;請參閱本頁底部的相容性表格以指導您的決策。請注意,此特性可能隨時停止工作。
非標準:此特性未標準化。我們不建議在生產環境中使用非標準特性,因為它們瀏覽器支援有限,並且可能會更改或被移除。但是,在沒有標準選項的特定情況下,它們可以是合適的替代方案。
File 介面的只讀屬性 lastModifiedDate 返回檔案的最後修改日期。沒有已知最後修改日期的檔案將返回當前日期。
值
一個 Date 物件,指示檔案最後修改的日期和時間。
示例
// fileInput is a HTMLInputElement: <input type="file" multiple id="my-file-input">
const fileInput = document.getElementById("my-file-input");
for (const file of fileInput.files) {
console.log(
`${file.name} has a last modified date of ${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)的倍數。
// reduced time precision (2ms) in Firefox 60
someFile.lastModifiedDate.getTime();
// Might be:
// 1519211809934
// 1519211810362
// 1519211811670
// …
// reduced time precision with `privacy.resistFingerprinting` enabled
someFile.lastModifiedDate.getTime();
// Might be:
// 1519129853500
// 1519129858900
// 1519129864400
// …
規範
儘管在 File API 規範的早期草案中存在,但此屬性已被移除,現已不再是標準。請改用 File.lastModified。
瀏覽器相容性
載入中…