Javascript日期问题,时区不正确 [英] Javascript Date issue, incorrect timezone
问题描述
我使用一些代码来制作2个JavaScript日期,将事件插入到日历组件。
日期以下列方式构建:
var endDate = new Date();
var startDate = new Date();
startDate.setDate(startDateDay);
startDate.setMonth(startDateMonth);
startDate.setFullYear(startDateYear);
startDate.setHours(2,0,0,0);
endDate.setDate(endDateDay);
endDate.setMonth(endDateMonth);
endDate.setFullYear(endDateYear);
endDate.setHours(2,0,0,0);
所以,日期是使用整数构建的。这些整数由输入决定,使用调试器可以看到正确的100%正确。
现在,病态描述了3个演练,2它正确地出现,1出现错误。
使用以下输入:
endDateDay = 20
endDateMonth = 9
endDateYear = 2014
提供以下日期对象作为结果:
Tue Oct 20 2014 02:00:00 GMT + 0200(W. Europe Daylight Time)
使用此输入:
endDateDay = 13
endDateMonth = 9
endDateYear = 2014
提供以下日期对象作为结果:
Tue Oct 13 2014 02:00:00 GMT + 0200(W. Europe Daylight Time)
现在使用此输入:
endDateDay = 27
endDateMonth = 9
endDateYear = 2014
提供以下日期对象作为结果:
Mon Oct 27 2014 02:00:00 ** GMT + 0100 **(W.欧洲标准时间)
正如您所见,由于某些奇怪的原因,TimeZone已关闭。这在我的应用程序中给出错误,我需要找到一种方法来解决它。虽然,我找不到任何解决方案,更不用说了解为什么会发生这种情况。
PS:我正在使用Google Chrome
答案确实是夏令时间的差异,我完全负责监督。感谢找到这一点,我也找到了一个解决我的问题的解决方案。
我使用这个链接进一步协助我,可能会帮助未来的人:
http://javascript.about.com/library/bldst.htm
干杯!
I got this strange JavaScript bug that I can seem to work arround or fix.
I am using some code to make 2 JavaScript dates, to insert events into a calendar component. The dates are built the following way:
var endDate = new Date();
var startDate = new Date();
startDate.setDate(startDateDay);
startDate.setMonth(startDateMonth);
startDate.setFullYear(startDateYear);
startDate.setHours(2, 0, 0, 0);
endDate.setDate(endDateDay);
endDate.setMonth(endDateMonth);
endDate.setFullYear(endDateYear);
endDate.setHours(2, 0, 0, 0);
So, the dates are built using integers. These integers are determined by input, and using the debugger I can see 100% positive they are coming in correctly. Now, ill describe 3 walkthroughs, 2 where it goes correctly and 1 where it goes wrong.
Using the following input:
endDateDay = 20
endDateMonth = 9
endDateYear = 2014
Gives the following date object as result:
Tue Oct 20 2014 02:00:00 GMT+0200 (W. Europe Daylight Time)
Using this input:
endDateDay = 13
endDateMonth = 9
endDateYear = 2014
Gives the following date object as result:
Tue Oct 13 2014 02:00:00 GMT+0200 (W. Europe Daylight Time)
Now, using this input:
endDateDay = 27
endDateMonth = 9
endDateYear = 2014
Gives the following date object as result:
Mon Oct 27 2014 02:00:00 **GMT+0100** (W. Europe Standard Time)
As you can see, for some strange reason the TimeZone is off. This gives errors in my application, and I need to find a way to get it fixed. Though, I cannot find any solution to it, let alone understand why it is actually happening.
PS: I am using Google Chrome
The answer was indeed the difference in the daylight savings time, which I completly oversaw. Thanks to finding this out I also found a solution to my problem.
I used this link to further assist me, might it help someone in the future: http://javascript.about.com/library/bldst.htm
Cheers!
这篇关于Javascript日期问题,时区不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!