Hello All,
This is doing my head in; I can't understand why dates in javascript behave in this way. The second variable (T2) is different whether you write it before you set hours on the third (T3). Can anyone please explain this to me??
OUTPUT:
Sat Jan 09 2010 21:09:03 GMT+0000 (GMT Standard Time)
Sat Jan 09 2010 22:09:03 GMT+0000 (GMT Standard Time)
Sat Jan 09 2010 23:09:03 GMT+0000 (GMT Standard Time)
Sat Jan 09 2010 21:09:03 GMT+0000 (GMT Standard Time)
Sat Jan 09 2010 23:09:03 GMT+0000 (GMT Standard Time)
Sat Jan 09 2010 23:09:03 GMT+0000 (GMT Standard Time)
---
CODE:
<html>
<body>
<script type="text/javascript">
T1 = new Date(); T2 = new Date(); T3 = new Date();
document.write(T1 + "<br>");
T2.setHours(T2.getHours()+1);
document.write(T2 + "<br>");
T3 = T2
T3.setHours(T3.getHours()+1);
document.write(T3 + "<br><br>");
document.write(T1 + "<br>");
document.write(T2 + "<br>");
document.write(T3 + "<br>");
</script>
</body>
</html>
This is doing my head in; I can't understand why dates in javascript behave in this way. The second variable (T2) is different whether you write it before you set hours on the third (T3). Can anyone please explain this to me??
OUTPUT:
Sat Jan 09 2010 21:09:03 GMT+0000 (GMT Standard Time)
Sat Jan 09 2010 22:09:03 GMT+0000 (GMT Standard Time)
Sat Jan 09 2010 23:09:03 GMT+0000 (GMT Standard Time)
Sat Jan 09 2010 21:09:03 GMT+0000 (GMT Standard Time)
Sat Jan 09 2010 23:09:03 GMT+0000 (GMT Standard Time)
Sat Jan 09 2010 23:09:03 GMT+0000 (GMT Standard Time)
---
CODE:
<html>
<body>
<script type="text/javascript">
T1 = new Date(); T2 = new Date(); T3 = new Date();
document.write(T1 + "<br>");
T2.setHours(T2.getHours()+1);
document.write(T2 + "<br>");
T3 = T2
T3.setHours(T3.getHours()+1);
document.write(T3 + "<br><br>");
document.write(T1 + "<br>");
document.write(T2 + "<br>");
document.write(T3 + "<br>");
</script>
</body>
</html>