最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript's Date.getTimezoneOffset() - Stack Overflow

programmeradmin4浏览0评论

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 based on EST while javascript gives an offset based on EDT. There is an hour difference between these two. Does anyone know how to make Javascript use the Standard Times like Windows? Thank you.

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 based on EST while javascript gives an offset based on EDT. There is an hour difference between these two. Does anyone know how to make Javascript use the Standard Times like Windows? Thank you.

Share Improve this question asked Jul 28, 2009 at 15:31 SquidScareMeSquidScareMe 3,2182 gold badges28 silver badges37 bronze badges 1
  • How are you retrieving the offset from the OS? – Rojo Commented Jul 28, 2009 at 16:07
Add a comment  | 

2 Answers 2

Reset to default 13

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();

Why not call getTimezoneOffset on a date where you know daylight saving time is not in force?

javascript:alert(new Date('1/1/2009').getTimezoneOffset())

That will give 300 (5 hours).

发布评论

评论列表(0)

  1. 暂无评论