Using and installing Date.php PHP Library to Convert Time between Timezones
Are you trying to do a timezone conversion using php? To do that you will first need to install the php-pear-Date library. Use the following yum command on CentOS/Redhat to install this library.
yum -y install php-pear-Date
Once the yum command installs the library you will be able to use it by adding an include line to your code. At the top of your php page add the following line.
See below for examples on how to convert from one timezone to another using php and the Date.php library. Copy and paste this into your own code to test it out.
$timezone_var = "America/New_York"; $start_stamp = $start_row1['stamp']; // this is a datetime from a MySQL database result $start_formated = date("m-d-Y h:i:s A",strtotime($start_stamp)); $f = new Date(strtotime($start_stamp)); $f->setTZByID("GMT"); $f->convertTZByID($timezone_var); $start_convert = $f->format("%m-%d-%Y %r %A");
The options for your United States time zones are as follows:
Eastern Timezone – America/New_York
Central Timezone – America/Chicago
Mountain Timezone – America/Denver
Pacific Timezone – America/Los_Angeles