Grab the RSS feed

Convert the time zone in PHP

In my application the client want to display the timezone in PST.
But default the time is displayed in MST.That is we get the time from server and displayed in aparticular page.
But the client want to show only in the particular page in PST.So I get the Program from PHP and use it.

Here I need to change the America/New_York to America/Los_Angels and it display the PST time

If you want it to display in different format change the argument in $format.Instead of g:i A T use D,h A T etc.

< ?php
function date_at_timezone($format, $locale, $timestamp=null){

if(is_null($timestamp)) $timestamp = time();

//Prepare to calculate the time zone offset
$current = time();

//Switch to new time zone locale
$tz = date_default_timezone_get();

//Calculate the offset
$offset = time() - $current;

//Get the date in the new locale
$output = date($format, $timestamp - $offset);

//Restore the previous time zone

return $output;


$t = time();

print date("g:i A T", $t); //4:16 PM PDT
print date_at_timezone("g:i A T", "America/New_York", $t); //7:16 PM EDT
print date_at_timezone("g:i A T", "Pacific/Samoa", $t); //12:16 PM SST
print date("g:i A T", $t); //4:16 PM PDT
? > 

Leave the comments to improve us….
Click Here to download as word document...


    Real Time Web Analytics