For one or another reason this code sample gives 48 hours instead of 24, can anyone explain me why the UTC time of a new month in javascript bugs orw hat I am doing wrong? Thanks for helping me out.
<script type="text/javascript">
function myFunction()
{
var d = (Date.UTC(2012,07,01) - Date.UTC(2012,06,30)) / 1000 / 3600;
alert(d);
}
myFunction();
</script>
Because month
6is July, since months are zero-based in JavaScript dates, and there are 31 days in July.If you want the number of hours between July 1st and June 30th, you want:
or more generally:
For more information, read the documentation on
Date.UTC.