note 61625 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 11 Jun 2006 11:42:50 +0000 |
| Subject: | note 61625 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114248@lists.php.net to get a copy of this message | ||
Note Submitter: Nathaniel Gibson
----
<?php
$timezone_mst = -7;
$timezone_est = -5;
echo tz_convert("2006-02-07 12:13:00",$timezone_mst,$timezone_est,"m/d/Y g:i
A");
//outputs: 02/07/2006 2:13 PM
function tz_convert($datetime,$tz_from,$tz_to,$format='Y-m-d H:i:s'){
return date($format,strtotime($datetime)+(3600*($tz_to - $tz_from)));
}
?>
This is my timezone converter function. It will convert a datetime field from one time zone to
another. It uses integers to represent the different timezones so that you can easily use a UTC
timezone value. It could easily be expanded to add a number of things like allowing a user to put
in longitudinal coordinates instead of integers for the from and to timezone arguments.