Tìm kiếm hỗ trợ

Tránh các lừa đảo về hỗ trợ. Chúng tôi sẽ không bao giờ yêu cầu bạn gọi hoặc nhắn tin đến số điện thoại hoặc chia sẻ thông tin cá nhân. Vui lòng báo cáo hoạt động đáng ngờ bằng cách sử dụng tùy chọn "Báo cáo lạm dụng".

Tìm hiểu thêm

javascript set date function sequence issue

  • 4 trả lời
  • 3 gặp vấn đề này
  • 2 lượt xem
  • Trả lời mới nhất được viết bởi 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...

Được chỉnh sửa bởi etroarthur vào

Tất cả các câu trả lời (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.

Được chỉnh sửa bởi etroarthur vào