Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- function countdown(yr,mon,d,h,m,pastmessage,target){
- //yr,mon,d,h,m are the Year, Month, Day, Hour, and Minute of the date the future event occurs
- //pastmessage is the message to display when the event has already happened
- //target is the target element to write the output to
- var today=new Date();
- var futuredate=new Date(yr,mon-1,d,h,m); //don't care why but the month has to be decremented
- dd=futuredate-today; //this should be the difference in the two dates in milliseconds
- dday=Math.floor(dd/(60*60*1000*24)*1); //find the number of days in dd
- dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1); //find the number of hours in dd
- dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1); //find the number of minutes in dd
- var wholedmin=dmin;if (dmin < 10){wholedmin="0"+dmin;} //convert to 2 digits if necessary
- dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1); //find the number of seconds in dd
- var wholedsec=dsec;if (dsec < 10){wholedsec="0"+dsec;} //convert to 2 digits if necessary
- if(futuredate<=today){
- document.getElementById(target).innerHTML=pastmessage; //write this if the date is past
- }
- else {
- document.getElementById(target).innerHTML= dday+ " days, "+dhour+":"+wholedmin+":"+wholedsec; //write this is futuredate is in the future
- }}
- </script>
- <div style="display:table-cell;background-image:url('http://www.highsnobiety.com/files/2013/01/star-wars-episode-7-vii.jpg');background-size:100% 100%;height:175px;width:276px;padding:5%;vertical-align:bottom;text-align:center;color:white;">
- <!--this div is the container for the element that gets updated every second. Reformat as needed.-->
- <h1 id="starwars">
- <!--this element's inner content is re-written by the countdown function --></h1>
- </div>
- <br />
- <div style="display:table-cell;background-image:url('http://cdn.bleedingcool.net/wp-content/uploads/2013/06/doctor-who-logo-black.jpg?f6a06b');background-size:100% 100%;height:225px;width:276px;padding:5%;vertical-align:bottom;text-align:center;color:white;">
- <!--this div is the container for the element that gets updated every second. Reformat as needed.-->
- <h1 id="drwho">
- <!--this element's inner content is re-written by the countdown function --></h1>
- </div>
- <script>
- var starwars = setInterval("countdown(2015,12,18,00,00,'It is out! Why are you not in the theater?','starwars')",1000); //this sets the starwars H1 element refreshing
- var drwho = setInterval("countdown(2013,11,23,13,00,'Mind: blown.','drwho')",1000); //this sets the drwho H1 element refreshing
RAW Paste Data