Dette websted vil have begrænset funktionalitet, mens vi gennemgår vedligeholdelse for at forbedre din oplevelse. Hvis en artikel ikke løser dit problem, og du vil stille et spørgsmål, har vi vores supportfællesskab, der venter på at hjælpe dig på @FirefoxSupport på Twitter og/r/firefox på Reddit.

Søg i Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Læs mere

javascript set date function sequence issue

  • 4 svar
  • 3 har dette problem
  • 2 visninger
  • Seneste svar af 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...

Ændret af etroarthur den

Alle svar (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.

Ændret af etroarthur den