如何使用php日期函数显示本地服务器时间的不同时间?

I understand that < ? echo date('l jS \of F Y h:i:s A'); ? > will get me "Tuesday 18th of June 2013 10:45:32 PM" or date and local time of where my server is located each I believe, it's Texas.

I want to show California time or PDT each is 2 hours behind my server time.

I have tried to change the timezone with < ? date_default_timezone_set('PDT'); ? > but it didn't change the result.

Please note that I'm not trying to get the data from the user computer (we can do that with JS or other user side language). I want to get the time from the server minus 2 hours.

This example shows how to get the current time in another time zone. The correct IANA time zone for US Pacific time is America/Los_Angeles.

$datetime = new DateTime('NOW', new DateTimeZone('America/Los_Angeles'));
echo $datetime->format('Y-m-d H:i:s');

Refer also to the PHP documentation on Date and Time.

Wikipedia has a good reference to the available time zone identifiers.

Get timestamp using time().

Adjust timestamp to the timezone you want to display.

Then display it with date().

$ts = time() - (2*60*60); // minus 2 hours
echo date('l jS \of F Y h:i:s A', $ts);

You can fix timezone to UTC to avoid influence from server time zone setting.

date_default_timezone_set('UTC');

Or just use gmdate() instead of date(), to display in UTC timezone.

$ts = time() - (2*60*60); // minus 2 hours
echo gmdate('l jS \of F Y h:i:s A', $ts);

This might give you an idea..

<?php
echo '2 hours behind my server time: '. date('Y-m-d h:m:i', strtotime('+2 hour')) ."
";
?>

this function will return you the time according to the time Zone

function currenttime($y,$m,$d){
        $timezone = new DateTimeZone("America/New_York");
        $date = new DateTime();
        $date->setTimezone( $timezone );
        $y=$date->format($y);
        $m=$date->format($m);
        $d=$date->format($d);
        $h=$date->format('H');
        $i=$date->format('i');
        $s=$date->format('s');
            return mktime($h,$i,$s,$m,$d,$y);
    }

to get desired time zone use this link http://www.php.net/manual/en/timezones.php