PDA

View Full Version : add day function problem - UTC shift problem



wouter
Dec 9th, 2002, 10:45 PM
The code below results in the following lines unfortunately when the code is executed on Sun 31 Oct 2004 I have an UTC shift? Why ? has it something to do with leap-year ?? -- It took me 3 hours to pinpoint the problem. How to solve ?
Tx

test1
date1 : Sun Oct 31 00:00:00 UTC+0200 2004
date2 : Sun Oct 31 23:00:00 UTC+0100 2004
test 2
date1 : Fri Oct 31 00:00:00 UTC+0100 2003
date2 : Sat Nov 1 00:00:00 UTC+0100 2003




<head>
<script language="JavaScript">
function add_days(adate,days)
{return new Date(adate.getTime() + (days * 1000 * 60 * 60 * 24));}

</script></head>
<body>
<script language="JavaScript">
date1 = new Date(2004,9,31);
date2 = add_days(date1,1);
document.write('date1 : '+date1+'<br>date2 : '+date2+'<br>');
date1 = new Date(2003,9,31);
date2 = add_days(date1,1);
document.write('date1 : '+date1+'<br>date2 : '+date2+'<br>');
</script>

</body></html>

PauletteB
Dec 9th, 2002, 11:35 PM
Daylight Savings Time ceases on the last Sunday of October at 02:00 am

First date is on DST while the following three are on Standard Time, hence the difference...