File: lastModifiedDate property
Note: This feature is available in Web Workers.
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
Thuộc tính chỉ đọc lastModifiedDate của giao diện File trả về ngày sửa đổi cuối cùng của tệp. Các tệp không có ngày sửa đổi cuối cùng sẽ trả về ngày hiện tại.
Giá trị
Một đối tượng Date cho biết ngày và giờ tệp được sửa đổi lần cuối.
Ví dụ
// 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}`,
);
}
Độ chính xác thời gian bị giảm
Để bảo vệ chống lại các cuộc tấn công thời gian và lấy dấu vân tay, độ chính xác của someFile.lastModifiedDate có thể bị làm tròn tùy thuộc vào cài đặt trình duyệt. Trong Firefox, tùy chọn privacy.reduceTimerPrecision được bật theo mặc định và mặc định là 2ms. Bạn cũng có thể bật privacy.resistFingerprinting, trong trường hợp đó độ chính xác sẽ là 100ms hoặc giá trị của privacy.resistFingerprinting.reduceTimerPrecision.microseconds, tùy theo giá trị nào lớn hơn.
Ví dụ, với độ chính xác thời gian bị giảm, kết quả của someFile.lastModifiedDate.getTime() sẽ luôn là bội số của 2, hoặc bội số của 100 (hoặc privacy.resistFingerprinting.reduceTimerPrecision.microseconds) khi bật privacy.resistFingerprinting.
// 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
// …
Thông số kỹ thuật
Mặc dù có mặt trong bản nháp đầu tiên của đặc tả File API, thuộc tính này đã bị xóa và hiện là phi tiêu chuẩn. Hãy sử dụng File.lastModified thay thế.