본 사이트는 여러분의 사용자 경험을 개선하기 위해 유지 보수를 진행하는 동안 기능이 제한됩니다. 도움말로 문제가 해결되지 않고 질문을 하고 싶다면 Twitter의 @FirefoxSupport 및 Reddit의 /r/firefox 채널을 활용하세요.

Mozilla 도움말 검색

고객 지원 사기를 피하세요. 저희는 여러분께 절대로 전화를 걸거나 문자를 보내거나 개인 정보를 공유하도록 요청하지 않습니다. "악용 사례 신고"옵션을 사용하여 의심스러운 활동을 신고해 주세요.

자세히 살펴보기

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 수정일시