Scalr_Util_DateTime::convertTz PHP Method

convertTz() public static method

Converts Time according to timezone settings of current user.
public static convertTz ( DateTime | string | integer $value, string $format = 'M j, Y H:i:s' ) : string
$value DateTime | string | integer DateTime object or Unix Timestamp or string that represents time.
$format string Format
return string Returns updated time in given format.
    public static function convertTz($value, $format = 'M j, Y H:i:s')
    {
        $timezone = '';
        if (Scalr_UI_Request::getInstance()->getUser()) {
            $timezone = Scalr_UI_Request::getInstance()->getUser()->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE);
            if (!$timezone) {
                $timezone = 'UTC';
            }
        }
        return self::convertDateTime($value, $timezone, $format);
    }

Usage Example

Example #1
0
 public function xGetListAction()
 {
     $this->request->defineParams(array('query', 'sort' => array('type' => 'json')));
     $hist = new WebhookHistory();
     $sql = "SELECT " . $hist->fields('h') . ", w.name AS webhookName, e.url\n                FROM " . $hist->table() . " h\n                INNER JOIN webhook_endpoints e ON h.endpoint_id = e.endpoint_id\n                INNER JOIN webhook_configs w ON h.webhook_id = w.webhook_id\n                WHERE e.env_id = ?\n                AND :FILTER:\n        ";
     $args = array($this->getEnvironmentId());
     if ($this->getParam('eventId')) {
         $sql .= ' AND h.event_id = ?';
         $args[] = $this->getParam('eventId');
     }
     $response = $this->buildResponseFromSql2($sql, array('created'), array('e.url', 'h.event_type'), $args);
     foreach ($response['data'] as $index => $row) {
         $hist = new WebhookHistory();
         $hist->load($row);
         $item = array();
         foreach (get_object_vars($hist) as $k => $v) {
             $item[$k] = $v;
         }
         $item['url'] = $row['url'];
         $item['webhookName'] = $row['webhookName'];
         $item['created'] = Scalr_Util_DateTime::convertTz($hist->created);
         unset($hist);
         $response['data'][$index] = $item;
     }
     $this->response->data($response);
 }
All Usage Examples Of Scalr_Util_DateTime::convertTz