javascript set date function sequence issue
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)
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.
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')
You're welcome
Does it still happen with UTC now being Apr 1?
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 수정일시