function setMySqlTimezone($returnError = false) { global $SETTINGS; $tzOffsetSeconds = date("Z"); // ignore offsets greater than 12 hours (illegal offset) if (abs($tzOffsetSeconds) > 12 * 60 * 60) { return; } // set mysql timezone $offsetString = convertSecondsToTimezoneOffset($tzOffsetSeconds); $query = "SET time_zone = '{$offsetString}';"; if (!mysql_query($query)) { $error = "MySQL Error: " . mysql_error() . "\n"; if ($returnError) { return $error; } else { die($error); } } }
<?php echo $timeZoneOptions; ?> </select> </td> </tr> <tr> <td><?php et('Local Time'); ?> </td> <td height="22"> <span id="localDate"><?php $offsetSeconds = date("Z"); $offsetString = convertSecondsToTimezoneOffset($offsetSeconds); $localDate = date("D, M j, Y - g:i:s A") . " ({$offsetString})"; echo $localDate; ?> </span> </td> </tr> <tr> <td><?php et('MySQL Time'); ?> </td> <td height="22"> <span id="mysqlDate"> <?php list($mySqlDate, $mySqlOffset) = mysql_get_query("SELECT NOW(), @@session.time_zone", true);
function getTimeZoneOptions($selectedTimezone = '') { global $SETTINGS; // get timezone name to offset $tzNameToOffset = array(); foreach (timezone_abbreviations_list() as $abbrZones) { foreach ($abbrZones as $abbrZoneArray) { $name = $abbrZoneArray['timezone_id']; $offset = convertSecondsToTimezoneOffset($abbrZoneArray['offset']); $tzNameToOffset[$name] = $offset; } } // sort from GMT-11:00 to GMT+14:00 $tzKeyValuesArray = array(); foreach ($tzNameToOffset as $tzName => $tzOffset) { $tzKeyValuesArray[] = array($tzName, $tzOffset); } uasort($tzKeyValuesArray, '_sortTimeZones'); $tzNameToOffset = array(); foreach ($tzKeyValuesArray as $keyAndValue) { list($key, $value) = $keyAndValue; $tzNameToOffset[$key] = $value; } // get options $options = ''; foreach ($tzNameToOffset as $tzName => $tzOffset) { if (!$tzName) { continue; } $isSelected = $tzName == $selectedTimezone; $selectedAttr = $isSelected ? 'selected="selected"' : ''; $options .= "<option value='{$tzName}' {$selectedAttr}>(GMT {$tzOffset}) {$tzName}</option>\n"; } return $options; }