Convert The Time Zone in PHP
Convert The Time Zone in PHP
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
http://www.php.net/manual/en/function.date.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();
date_default_timezone_set($locale);
//Calculate the offset
$offset = time() - $current;
//Get the date in the new locale
$output = date($format, $timestamp - $offset);
//Restore the previous time zone
date_default_timezone_set($tz);
return $output;
}
//Examples
$t = time();
?>