Page 1 of 1

PHP Time Zone - timestamp

Posted: Mon Jul 12, 2010 5:34 am
by patel.manjeet
Hi ,
I am using facing some problem to getting local timestamp for different time zone setting .

please any one can help me.

I am using following code.

Code: Select all

echo "default:";
echo "<br/>";
echo $today = date("F j, Y, g:i a");                 
echo "<br/>";
echo $today = time(); 	
echo "<br/>";

date_default_timezone_set('America/Maceio');
echo "for America/Maceio:";
echo "<br/>";
echo $today = date("F j, Y, g:i a");              
echo "<br/>";
echo $today = time(); 	
echo "<br/>";
---------------------------------------------

This code give me correct date for server time zone and 'America/Maceio'
but function time() give same timestamp for both before and after date_default_timezone_set....

i.e time() function return server timestamp only not as per date_default_timezone_set....



This is sample output i am getting now

Code: Select all

default:
July 12, 2010, 10:30 am
1278930629

for America/Maceio:
July 12, 2010, 7:30 am
1278930629

Re: PHP Time Zone - timestamp

Posted: Mon Jul 12, 2010 7:15 am
by PHPHorizons
That is the expected behavior. The timestamp is timezone agnostic. It's when you take that timestamp and convert it into a human readable date that the timezone comes into play.

Cheers

Re: PHP Time Zone - timestamp

Posted: Mon Jul 12, 2010 7:54 am
by patel.manjeet
Thanks,

any other way to convert server timestamp to local timestamp.

Re: PHP Time Zone - timestamp

Posted: Mon Jul 12, 2010 7:57 am
by PHPHorizons
There is no such thing as a "server timestamp" or a "local timestamp".

There is only a timestamp. No matter what timezone, no matter where in the world, a timestamp created at the same time as another timestamp will be exactly equal. I.e., timestamps are timezone agnostic.

Cheers