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
matthiasone
Forum Contributor
Posts: 117 Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:
Post
by matthiasone » Mon Dec 30, 2002 10:58 am
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 » Mon Dec 30, 2002 7:00 pm
T - Timezone setting of this machine; e.g. "EST" or "MDT"
Elmseeker
Forum Contributor
Posts: 132 Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA
Post
by Elmseeker » Mon Dec 30, 2002 7:06 pm
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 » Wed Jan 01, 2003 6:48 am
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"
Elmseeker
Forum Contributor
Posts: 132 Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA
Post
by Elmseeker » Wed Jan 01, 2003 7:11 am
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 » Thu Jan 02, 2003 10:21 am
thanks for the help. That solved the problem