note 77181 deleted from function.gmdate by nlopess
| From: | nlopess@php.net | Date: | Sat, 01 Sep 2007 11:58:10 +0000 |
| Subject: | note 77181 deleted from function.gmdate by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-129994@lists.php.net to get a copy of this message | ||
Note Submitter: Sam Yong - hellclanner [at] live dot com
----
Many people have been looking for such a function to manage members' time. I looked at so many
functions for this purpose and came up with this.
<?php
/*
A simple function to change timezone of a time to the desired timezone.
The function returns an array of timezone data and time.
*/
function cTimezone($time = false, $tzHours = +8, $dst = true){
if(!is_int($tzHours)){$tzHours = intval($tzHours);}
$timearray = array();
$h = $tzHours;
if ($dst) {
$daylight_saving = date('I');
if ($daylight_saving){
if ($h < 0){ $h=$h+1; } else { $h=$h-1; }
}
}
if(!$time){$time = time();}
$ms = $h * 3600;
$timestamp = ($time+($ms));
$timearray = array(
'h' => gmdate("G",$timestamp),
'm' => gmdate("m",$timestamp),
'j' => gmdate("j",$timestamp),
'n' => gmdate("n",$timestamp),
'Y' => gmdate("Y",$timestamp),
's' => gmdate("s",$timestamp),
'GMT' => $h,
'0' => gmdate("U",$timestamp)
);
return $timearray;
}
?>
Used successfully in http://betapod.hellclanner.com/