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 September 20, known as National Vegas Day in honor of Dean Martin.
First we need two methods attached to the date object to get to Sept. 20th. Next an if statement is needed
to determine if we are passed Sept. the 20th of the current year or if the date did not yet occur.
<script type="text/javascript"> var Sept20=new Date();//Here we instantiate the Date object for use. Sept20.setFullYear(Sept20.getFullYear(),8,20);//Here we are setting to a specific date. document.write("Current Year's Sept. 20, " + Sept20.getFullYear() ); var today=new Date();//Here we re-assign the date object to today. document.write("<br />") if (Sept20>today) { var Dayto20= (Sept20-today); document.write("<p> JavaScript time to the next Sept. 20th: " + Dayto20 + "<br /> which is ridiculous!</p>"); var DayConv=(Dayto20)/(1000*60*60*24); DayConv=Math.round(DayConv); document.write(DayConv + ": Days until Sept. 20th"); } else { Sept20.setFullYear(Sept20.getFullYear()+1,8,20); //document.write("<p>Coming Sept. 20th: " + Sept20 + "</p>"); var Dayto20 =(Sept20-today); document.write("<p> JavaScript time to the next Sept. 20th: " + Dayto20 + "<br /> which is ridiculous!</p>"); var DayConv=(Dayto20)/(1000*60*60*24); DayConv=Math.round(DayConv); document.write(DayConv + ": Days until Sept. 20th"); } </script>
Return to Table of Contents