PHP Time Zone - timestamp

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
patel.manjeet
Forum Newbie
Posts: 4
Joined: Mon Jul 12, 2010 5:17 am

PHP Time Zone - timestamp

Post 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
Last edited by patel.manjeet on Mon Jul 12, 2010 7:52 am, edited 1 time in total.
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: PHP Time Zone - timestamp

Post 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
patel.manjeet
Forum Newbie
Posts: 4
Joined: Mon Jul 12, 2010 5:17 am

Re: PHP Time Zone - timestamp

Post by patel.manjeet »

Thanks,

any other way to convert server timestamp to local timestamp.
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: PHP Time Zone - timestamp

Post 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
Post Reply