Javascript's Date.getTimezoneOffset()

前端 未结 2 1716
天命终不由人
天命终不由人 2020-12-09 00:41

I\'m trying to compare a GMT time offset from the operating system to a GMT time offset from Javascript\'s Date.getTimezoneOffset(). The problem is windows gives an offset b

2条回答
  •  旧时难觅i
    2020-12-09 01:15

    Note, that the first posted answer does only work in a half of all cases, thus not work at all on average.

    First january is known not to be in daylight saving time only in the northern hemisphere. However that's only half of the world.

    var jan = new Date( 2009, 0, 1, 2, 0, 0 ), jul = new Date( 2009, 6, 1, 2, 0, 0 );
    var offset = ( jan.getTime() % 24 * 60 * 60 * 1000 ) > 
                 ( jul.getTime() % 24 * 60 * 60 * 1000 )
                 ?jan.getTimezoneOffset() : jul.getTimezoneOffset();
    

提交回复
热议问题