View Full Version : Can you format php's date() to use a timezone?

Bry Man
06-29-2005, 08:26 PM

I was wondering if it were possible to format php's date() function to display in a specific time zone, mine which is -07:00, and not the servers which is +02:00. Is this possible? I *thought* it was something like O-07:00 but O only displays ther servers timezone...any help is appreciated.

06-29-2005, 10:27 PM
just find out what the servers time zone is and add or subtract to obtain the right figure?

Bry Man
06-29-2005, 10:30 PM
How would you go about doing that? I didnt think that you could subtract or add time to the servers time, thats what I thought that O -07:00 would do. Im using it as part of a user logging script that...logs users, and the time is kinda important. Im sorry but im not well versed in some areas of php, simple and complex as they may be. Could you perhaps provide an example please? Thanks for the reply though.

06-30-2005, 01:31 AM
Try this:

$hour_difference = "7";

$timeadjust = ($hour_difference * 60 * 60);

$local_timestamp = date("l, d F Y h:i a",time() - $timeadjust);

print ("$local_timestamp");

your hour difference from the server is -7, which is why you are subtracting $timeadjust from time(), instead of adding it....

Bry Man
06-30-2005, 02:20 AM
Thanks for the help, that works great :thumbsup:

06-30-2005, 02:34 AM
you're welcome... ;)