/    Sign up×
Community /Pin to ProfileBookmark

Displaying World/City Times

I want to do a similar effect on my site as this site has done

[url]http://www.re-title.com/[/url]

I think this is the part of the javascript code that’s giving the time zones, the second load of code just seems to be dealing with a user clicking on an actual city name to produce a search function, which I don’t need.

Any help or a point in the right direction would be greatly appreciated.

[CODE]<script type=”text/javascript”>
function formatWithOffset(offset) {
var time = new Date();

time.setTime(time.getTime() + offset*60*60*1000);
h = time.getUTCHours();
h=((h < 10) ? “0” : “”) + h;
m = time.getUTCMinutes();
m=((m < 10) ? “0” : “”) + m;
s = time.getUTCSeconds();
s=((s < 10) ? “0” : “”) + s;

return(h + ‘:’ + m + ‘:’ + s);
}

function setWorldTimes() {

var time = new Date()
var DSTOffser;

tsoffset = time.getTimezoneOffset();

DSTOffset=1;
document.getElementById(“londonTime”).innerHTML = formatWithOffset(0+DSTOffset);
document.getElementById(“berlinTime”).innerHTML = formatWithOffset(1+DSTOffset);
document.getElementById(“newyorkTime”).innerHTML = formatWithOffset(-5+DSTOffset);
document.getElementById(“chicagoTime”).innerHTML = formatWithOffset(-6+DSTOffset);
document.getElementById(“laTime”).innerHTML = formatWithOffset(-8+DSTOffset);

timer = setTimeout(“setWorldTimes()”,1000);

return true;
}

function quickSearchOnFocus(obj) {
}

</script>[/CODE]

And this is my table, I have tried to call London time and Berlin time but with no luck.

[code=html]<table width=”100%” border=”0″ cellpadding=”5″>
<tr class=”city”>
<td><div align=”center”>London</div></td>
<td><div align=”center”>Amsterdam</div></td>
<td><div align=”center”>New York</div></td>
<td><div align=”center”>Berlin</div></td>
<td><div align=”center”>Rio De Janerio</div></td>
<td><div align=”center”>Paris</div></td>
<td><div align=”center”>Miami</div></td>
<td><div align=”center”>Buenos Aires</div></td>
<td><div align=”center”>Chicago</div></td>
<td><div align=”center”>Bogota</div></td>
</tr>
<tr>
<td><div id=”londonTime” align=”center”>00:00:00</div></td>
<td><div align=”center”>00:00:00</div></td>
<td><div align=”center”>00:00:00</div></td>
<td><div id=”berlinTime” align=”center”></div></td>
<td><div align=”center”>00:00:00</div></td>
<td><div align=”center”>00:00:00</div></td>
<td><div align=”center”>00:00:00</div></td>
<td><div align=”center”>00:00:00</div></td>
<td><div align=”center”>00:00:00</div></td>
<td><div align=”center”>00:00:00</div></td>
</tr>
</table>[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@deeperauthorJul 23.2009 — Or if there is an easier/simpler/cleaner way to do this? Maybe using jQuery it would be good to know.
Copy linkTweet thisAlerts:
@KorJul 23.2009 — You may try one of my world clocks, if it will suit to you:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;script type="text/javascript"&gt;
//Universal clock 2007
//Genuine code by Corneliu Lucian "Kor" RUSU, corneliulucian[at]gmail[dot]com
var wd=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
var D=[
['Bucharest',120,60],// [city, standard time zone(minutes), DST(minutes)]
['Madrid',60,60],
['New York',-300,60],
['Nairobi',180,0],
['London',0,60]
]
function calc(){
var spans=document.getElementById('zonediv').getElementsByTagName('span')
for(var i=0;i&lt;D.length;i++){
var t=new Date();
t.setTime(t.getTime()+(t.getTimezoneOffset()*60000)+((D[i][1]+D[i][2])*60000));//the zone's time
var Dy=t.getFullYear();
var Dd=t.getDate()&lt;10?'0'+t.getDate():t.getDate();
var Dm=t.getMonth()&lt;9?'0'+(t.getMonth()+1):t.getMonth()+1;
var Dh=t.getHours()&lt;10?'0'+t.getHours():t.getHours();
var Di=t.getMinutes()&lt;10?'0'+t.getMinutes():t.getMinutes();
var Ds=t.getSeconds()&lt;10?'0'+t.getSeconds():t.getSeconds();
var Dz=wd[t.getDay()];
spans[i].firstChild.data=Dh+':'+Di+':'+Ds+' - '+Dz+' '+Dd+'/'+Dm+'/'+Dy;
}
setTimeout('calc()',1000)
}
onload=function(){
var root = document.getElementById('zonediv');
for(var i=0;i&lt;D.length;i++){
root.appendChild(document.createTextNode(D[i][0]+' '))
var sp= document.createElement('span');
sp.appendChild(document.createTextNode(' '));
root.appendChild(sp);root.appendChild(document.createElement('br'))
}
calc();
}
&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;div id="zonediv"&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

Copy linkTweet thisAlerts:
@deeperauthorJul 23.2009 — Hey thats great, thanks.

How can I call the individual city time to include in my table, instead of calling the whole #zonediv ?
×

Success!

Help @deeper spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...