Monday, 26 September 2011

SWTOR release date JavaScript count down clock

I have added a JavaScript count down clock to the site, based on a count down clock from JavaScript Kit. This counts down to the EU release of Star Wars The Old Republic.

This, in Blogger terms, is a HTML/JavaScript widget with the following content:
<div id="countdowndiv"></div>
Count down until any date script-
By JavaScript Kit (
Over 200+ free scripts here!
//change the text below to reflect your own,
var before="SWTOR"
var current="Today is release day!"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[m-1]+" "+d+", "+yr
else {
var theDiv = document.getElementById("countdowndiv");
theDiv.innerHTML = dday+ " days "+dhour+" hours "+dmin+" minutes"
//enter the count down date using the format year/month/day
The "countdowndiv" DIV element right at the top is where the message will appear, so can be styled using CSS to whatever you wish. At the end, the call to countdown(2011,12,22) kicks it off for the 22nd of December 2011.

This line here renders the actual text:
theDiv.innerHTML = dday+ " days "+dhour+" hours "+dmin+" minutes"
So you can change that to whatever you wish. I also removed the seconds, which are present in the variable dsec and can be added back in again.

This line waits for 10 seconds and recalculates the clock:
So you can drop that value to 1000 if you want to check every second. 10 seconds seems fine to me.

Feel free to use this on your own site!

No comments:

Post a Comment