Forum Moderators: coopster
I'm also interested in having a line of clocks next to each other i.e. showing the time in London, New York, Paris, Bangkok etc etc.... how could I achieve this?
Note that I don't want to use Javascript and I'm not bothered if the time doesn't update browser side.
//this function takes in a string
//time zone and returns the current time
//for that. right now it takes in either
//yourZone1 and yourZone2 but you could
//modify these to take in whatever string
//makes the most sense for you. i.e. london/england
//or usCentralTime
function getTime($timeZone){
//this is assuming that you have figured
//out that that yourZone1 is the current
//time on your php server + 4 hours
if($timeZone == "yourZone1"){
return("The current time for $timeZone is " . date("Y-m-d H:i:s", strtotime("+4 hours")));
}//if
//this is assuming that you have figured
//out that that yourZone2 is the current
//time on your php server - 3 hours
else if($timeZone == "yourZone2"){
return("The current time for $timeZone is " . date("Y-m-d H:i:s", strtotime("-3 hours")));
}//if
//else you didn't pass in a correct time
else{
return("You didn't pass in a time that I know.");
}
}//getTime
The rest of the script runs in Hong Kong time.
Or, change it again in mid-script, if you need to.
Read The Fine Manual: getenv() , putenv()
Don't simply use aritmetic and 'how many hours forward/back you need to go' to move from timezone to timezone. You will get bitten by various Daylight Savings, Summer Time, etc. switches.
Jonesy