Time Zone problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

Time Zone problem

Post 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.
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

T - Timezone setting of this machine; e.g. "EST" or "MDT"
User avatar
Elmseeker
Forum Contributor
Posts: 132
Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA

Post 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...
laserlight
Forum Commoner
Posts: 28
Joined: Wed Jan 01, 2003 6:41 am

Post by laserlight »

this function should return the current time:

Code: Select all

function mydate($offset) &#123;
	$offset *= 3600;
	return gmdate(<format string>, mktime() + $offset); 
&#125;
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"
User avatar
Elmseeker
Forum Contributor
Posts: 132
Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA

Post 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...:)
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

Post by matthiasone »

thanks for the help. That solved the problem
Post Reply