Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#infocypruseutime {
text-align:center;
font-size:90%;
font-family:sans-serif;
}
</style>
<script type="text/javascript">
var findCyprusEuTimeDST = function(year, mo, dt) {
/***********************
DST in Cyprus-EU Zone
***********************/
/* set defaults if necessary */
dt = dt | 1; mo = mo || 2; year = year | new Date().getUTCFullYear();
/* declare our variables - using 12 noon should avoid any unpleasantness from DST */
var oDate = new Date(year,mo,dt); oDate.setHours(12); var day = oDate.getDay(), mm, dd = oDate.getDate() - day, yy,
/* day will be how far we are from the previous Sunday, subtracting it from the date and will give us Sunday */
dd = dd + 7; /* advance to the next Sunday */
oDate.setDate(dd); /* pass our new date back to the oDate Date object for any change in month figure */
mm = oDate.getMonth();
dd = oDate.getDate();
yy = oDate.getFullYear();
if (mm == mo){ // if we haven't advanced the month yet we either have the Sunday we are looking for, or are still checking
findCyprusEuTimeDST.dat[(mo == 2? 0 : 1)] = Date.parse(new Date(oDate.setUTCHours(1))); // using UTC 01:00:00 should place us at the DST transition moment in zone +0200
findCyprusEuTimeDST(yy,mm,dd);
}
else if (mm - 1 == 2) findCyprusEuTimeDST('', 9);
else if (mm - 1 == 9) findCyprusEuTimeDST.dat[2] = 'Done!';
}
findCyprusEuTimeDST.dat = [];
findCyprusEuTimeDST();
function cyprusEuTime(){
if(findCyprusEuTimeDST.dat.length != 3){
setTimeout('cyprusEuTime()', 300);
return;
}
var d = new Date(),
dp = Date.parse(d),
dst = dp >= findCyprusEuTimeDST.dat[0] && dp < findCyprusEuTimeDST.dat[1]? 1 : 0;
d.setMinutes(d.getMinutes()+d.getTimezoneOffset()+(2+dst)*60);
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
sfx = {1:'st', 2:'nd', 3:'rd', 21:'st', 22:'nd', 23:'rd', 31:'st'},
pad = function(v){return v.toString().length == 2? v : '0' + v;},
dd = days[d.getDay()],
mn = months[d.getMonth()],
dt = d.getDate(),
yy = d.getFullYear(),
hh = pad(d.getHours()),
mm = pad(d.getMinutes()),
ss = pad(d.getSeconds());
sfx = sfx[dt]? sfx[dt] : 'th';
cyprusEuTime.dat = dd+' '+mn+' '+dt+sfx+' '+yy+' '+hh+':'+mm+':'+ss+' GMT+0'+(2+dst)+'00\x0d\x0a'+
(dst? 'Eastern European Summer ' : 'Eastern European Standard ')+'Time Cyprus-EU';
document.getElementById('infocypruseutime').firstChild.nodeValue = cyprusEuTime.dat;
setTimeout(function(){findCyprusEuTimeDST.dat = []; findCyprusEuTimeDST(); cyprusEuTime();}, 1000);
}
window.onload = cyprusEuTime;
</script>
</head>
<body>
<pre id="infocypruseutime"> </pre>
</body>
</html>
The code could probably be simplified, and there could be a bug, if say the user's computer changes to DST at an inopportune moment, but I think I got away from that by using noon where noted in the code. It will depend upon the user's clock being accurate. It also depends upon Cyprus continuing to use the same rules for changing to and from Summer Time. Here is an alternative - a link to a free Flash clock from worldtimeserver.com:
Bookmarks