Where did you install Firefox from? Help Mozilla uncover 3rd party websites that offer problematic Firefox installation by taking part in our campaign. There will be swag, and you'll be featured in our blog if you manage to report at least 10 valid reports!

Tìm kiếm hỗ trợ

Tránh các lừa đảo về hỗ trợ. Chúng tôi sẽ không bao giờ yêu cầu bạn gọi hoặc nhắn tin đến số điện thoại hoặc chia sẻ thông tin cá nhân. Vui lòng báo cáo hoạt động đáng ngờ bằng cách sử dụng tùy chọn "Báo cáo lạm dụng".

Learn More

Date.prototype.toJSON() and Date.prototype.toISOString() discrepancy

  • 6 trả lời
  • 0 gặp vấn đề này
  • 58 lượt xem
  • Trả lời mới nhất được viết bởi Mathias Frost

more options

console.log(new Date().toJSON()); console.log(new Date().toISOString());

// Actual output: // 2023-05-27T04:21:13.004Z // 2023-05-27T06:21:13.005Z

// Expected output: // 2023-05-27T06:21:13.004Z // 2023-05-27T06:21:13.005Z

This happens only on Firefox and Firefox Developer Edition on one of my PCs and not the other. Firefox is version 113.0.2 (64-bit) and DE is 114.0b9 (64-bit)

Anyone experienced this before?

console.log(new Date().toJSON()); console.log(new Date().toISOString()); // Actual output: // 2023-05-27T04:21:13.004Z // 2023-05-27T06:21:13.005Z // Expected output: // 2023-05-27T06:21:13.004Z // 2023-05-27T06:21:13.005Z This happens only on Firefox and Firefox Developer Edition on '''one''' of my PCs and '''not''' the other. Firefox is version 113.0.2 (64-bit) and DE is 114.0b9 (64-bit) Anyone experienced this before?

Giải pháp được chọn

Do you have enabled "Resist Fingerprinting" if you check this pref on the about:config page?

Đọc câu trả lời này trong ngữ cảnh 👍 0

Tất cả các câu trả lời (6)

more options

Giải pháp được chọn

Do you have enabled "Resist Fingerprinting" if you check this pref on the about:config page?

more options

Setting `privacy.resistFingerprinting` to `true` fixed the discrepancy, but... why?

more options

Note that best is to keep this pref set to false as this can cause issues.

I can't replicate this, with both RFP disabled and enabled I get the same UTC output as expected. Does it make a difference what timezone is set in the OS ?

Do you get the correct local time via console.log(new Date()) ?

more options

Yeah, I noticed some undesirable side-effects from having that to true, but weirdly enough, when turning it back to false, the issue is still fixed:

console.log(new Date()) // Date Sun May 28 2023 18:49:13 GMT+0200 (Central European Summer Time)

console.log(new Date().toJSON()) // 2023-05-28T16:49:51.947Z

console.log(new Date().toISOString()) // 2023-05-28T16:50:10.427Z

Seconds diff is because I executed them individually.

End even werider (or not, depending on whether or not DE and normal Firefox share config), on Developer Edition, where I have not toggled privacy.resistFingerprinting, the issue is also fixed:

console.log(new Date()) // Date Sun May 28 2023 18:53:43 GMT+0200 (Central European Summer Time)

console.log(new Date().toJSON()) // 2023-05-28T16:53:54.024Z

console.log(new Date().toISOString()) // 2023-05-28T16:54:03.475Z

Not sure what to make of this :D Maybe some weird, edge-case bug...

more options

Did you get the local time in the case where it went wrong ?

more options

Yes, new Date() and new Date().toISOString() gave correct time