Javascript日期问题,时区不正确

编程入门 行业动态 更新时间:2024-10-24 10:16:56
本文介绍了Javascript日期问题,时区不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用一些代码来制作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

解决方案

答案确实是夏令时间的差异,我完全负责监督。感谢找到这一点,我也找到了一个解决我的问题的解决方案。

我使用这个链接进一步协助我,可能会帮助未来的人: javascript.about/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: javascript.about/library/bldst.htm

Cheers!

更多推荐

Javascript日期问题,时区不正确

本文发布于:2023-11-30 04:06:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648660.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不正确   时区   日期   Javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!