.
<script type="text/javascript"> var d =new Date(); document.write(d + "<br />"); document.write(d.getTime() + " miliseconds since 1970/01/01" + "<br />"); </script>
Note: Time is reported in milliseconds since 1970 for JavaScript. This requires a math conversion.
24 X | 60 X | 60 X | 1000 = 86,400,000 |
hours in a day | minutes in a hour | seconds in a minute | 1000 milliseconds in a second |
Now we will use Javascript to calculate the days to April 15, known as tax day.
First we need two methods attached to the date object to get to Apr. 15th. Next an if statement is needed
to determine if we are passed Apr. the 15th of the current year or if the date did not yet occur.
<script type="text/javascript"> var APR15=new Date();//Here we instantiate the Date object for use. APR15.setFullYear(APR15.getFullYear(),3,15);//Here we are setting to a specific date. document.write("Current Year's April 15, " + APR15.getFullYear() ); var today=new Date();//Here we re-assign the date object to today. document.write("<br />") if (APR15>today) { var Dayto15= (APR15-today); document.write("<p> JavaScript time to the next Apr. 15th: " + Dayto15 + "<br /> which is ridiculous!</p>"); var DayConv=(Dayto15)/(1000*60*60*24); DayConv=Math.round(DayConv); document.write(DayConv + ": Days until next April 15th"); } else { APR15.setFullYear(APR15.getFullYear()+1,3,15); //document.write("<p>Coming April 15: " + APR15 + "</p>"); var Dayto15 =(APR15-today); document.write("<p> JavaScript time to the next Apr. 15th: " + Dayto15 + "<br /> which is ridiculous!</p>"); var DayConv=(Dayto15)/(1000*60*60*24); DayConv=Math.round(DayConv); document.write(DayConv + ": Days until next April 15th"); } </script>
Return to Table of Contents