简体   繁体   中英

set / get VS setUTC / getUTC

I'm working with dates and I was wondering if there was a border case where:

var d2 = new Date(d);
d.setHours(d.getHours() + n) !== d2.setUTCHours(d2.getUTCHours() + n)

..?

In the US this year (2016), Daylight Savings time starts at 2:00AM on Sunday 13 March:

var dstDate = new Date(2016, 2, 13);
var dstUTC = new Date(dstDate);

If we add 3 hours as per your question:

dstDate.setHours(dstDate.getHours() + 3);
console.log(dstDate); // 3:00AM

dstUTC.setUTCHours(dstUTC.getUTCHours() + 3);
console.log(dstUTC); // 4:00 AM

(My local time zone is UTC-6.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM