为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

javascript set date function sequence issue

  • 4 个回答
  • 3 人有此问题
  • 2 次查看
  • 最后回复者为 etroarthur

more options

This is a javascript date error that occurs in FireFox, Chrome and IE. In setting the date using utc functions the order in which the functions are used can cause the wrong date set be set.

 var d = new Date();  
       d.setUTCFullYear(2012,1,26);
 correctly sets the date: 
Sun Feb 26 2012 10:10:33 GMT-0500 (Eastern Standard Time)
var d = new Date();  
       d.setUTCFullYear( 2012 );   
       d.setUTCMonth( 1 );    
       d.setUTCDate( 26 );
 incorrectly sets the date: 

Mon Mar 26 2012 11:10:33 GMT-0400 (Eastern Daylight Time)

var d = new Date();

      d.setUTCDate( 26 );
      d.setUTCMonth( 1 );    
     d.setUTCFullYear( 2012 );     
 correctly sets the date: 

Sun Feb 26 2012 10:10:33 GMT-0500 (Eastern Standard Time)


It appears the full date isn't being used to re-validate/calc the date upon setting single utc parms.

Thanks.

This happens Windows 7, NOOK...

This is a javascript date error that occurs in FireFox, Chrome and IE. In setting the date using utc functions the order in which the functions are used can cause the wrong date set be set. var d = new Date(); d.setUTCFullYear(2012,1,26); correctly sets the date: Sun Feb 26 2012 10:10:33 GMT-0500 (Eastern Standard Time) var d = new Date(); d.setUTCFullYear( 2012 ); d.setUTCMonth( 1 ); d.setUTCDate( 26 ); incorrectly sets the date: Mon Mar 26 2012 11:10:33 GMT-0400 (Eastern Daylight Time) var d = new Date(); d.setUTCDate( 26 ); d.setUTCMonth( 1 ); d.setUTCFullYear( 2012 ); correctly sets the date: Sun Feb 26 2012 10:10:33 GMT-0500 (Eastern Standard Time) It appears the full date isn't being used to re-validate/calc the date upon setting single utc parms. Thanks. This happens Windows 7, NOOK...

由etroarthur于修改

所有回复 (4)

more options

A good place to ask advice about web development is at the MozillaZine "Web Development/Standards Evangelism" forum.

The helpers at that forum are more knowledgeable about web development issues.
You need to register at the MozillaZine forum site in order to post at that forum.

more options

Thanks, I thought it might of been the wrong place but figured I should pass it on anyway. (couldn't easily find where to post possible 'bugs')

more options

You're welcome

Does it still happen with UTC now being Apr 1?

more options

Short answer; no, doesn't happen Apr 1.
Longer answer; I set up a page to loop through everyday of a given month.
(http://itriware.com/lab/test/datetest.html)
Changing the machine date results in:

  • md:30-Mar - no good for the month of Feb.
  • md:31-Mar - no good for the months: Feb, Apr, Jun, Sep, Nov.
  • md:01-Apr - ok
  • md:30-Apr - no good for the month of Feb.
  • md:31-May - no good for the months: Feb, Apr, Jun, Sep, Nov.
(md=machine date)

Seems to be an end of the month issue, depending on the sequence of setting the utc parms, the month rolls over but isn't adjusted back when setting the next parm...sometimes.

After thinking about it; Seems that if the machine day of month is greater than the # of days in the requested month it fails, hence feb always fails and only requested months with 30 days fail when the machine date is the 31st. In the sequence setUTCFullYear, setUTCMonth, setUTCDate.

由etroarthur于修改