...

View Full Version : Time based on a timezone



tomharto
10-04-2011, 12:24 AM
I have a site where users enter there certain timezome (+1, +4, -8 etc) and i want to display a clock with the local time on their profile page so when people view there profile they can see currently what time it is for them.

I currently a have this.



function timeclock()
{
var t=setTimeout("startclock()",500);
}

function startclock()
{

var x = new Date();
var hour = x.getHours();
var min = x.getMinutes();
var sec = x.getSeconds();
if (hour<10){hour="0"+hour}
if (min<10){min="0"+min}
if (sec<10){sec="0"+sec}
document.getElementById("clock").innerHTML=hour+":"+min+":"+sec;
timeclock();
}



Is it possible to alter the date dependent on the timezone? Maybe put startclock(timezone) andchange it to new Date(timezone);?

Old Pedant
10-04-2011, 12:47 AM
Sure.


function startclock( offset )
{
var x = new Date();
x.setTime( x.getTime() + offset * 60 * 60 * 1000 ); // add/subtract offset hours
...

tomharto
10-04-2011, 12:48 AM
thanks :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum