Page 1 of 1
Time Zone problem
Posted: Mon Dec 30, 2002 10:58 am
by matthiasone
I need to be able to get current date and time in CST, but my pages are hosted on a site in EST. Any ideas on how to get a timestamp for CST?
currently I am using
Code: Select all
$nowunix = strtotime("now");
$now = date("Y-m-d H:i:s",$nowunix);
but this get me the EST time.
Posted: Mon Dec 30, 2002 7:00 pm
by oldtimer
T - Timezone setting of this machine; e.g. "EST" or "MDT"
Posted: Mon Dec 30, 2002 7:06 pm
by Elmseeker
Well, you know that CST is 1 hour behind EST and q hour is 3600 seconds so why not just try:
Code: Select all
<?
$nowunix = strtotime("now") - 3600;
$now = date("Y-m-d H:i:s",$nowunix);
echo $now." CST";
?>
That should pretty much do what you need...
Posted: Wed Jan 01, 2003 6:48 am
by laserlight
this function should return the current time:
Code: Select all
function mydate($offset) {
$offset *= 3600;
return gmdate(<format string>, mktime() + $offset);
}
For example, I'm in Singapore (GMT +8), so I might use
echo mydate(8);
after setting the format string to say "h:ia, d M Y"
Posted: Wed Jan 01, 2003 7:11 am
by Elmseeker
Something like this would be very useful if you have users from different time zones using the site, registered users could let you know what time zone they are in and then it's a simple matter of having the server calculate the appropriate time to display the users local time when they are visiting the site...

Posted: Thu Jan 02, 2003 10:21 am
by matthiasone
thanks for the help. That solved the problem