示例#1
0
 /**
  * Get the datetime object, in site's time zone, if the datetime string was valid
  *
  * @param string $datetime_string The datetime string in UTC time zone, that needs to be converted to a DateTime object.
  * @param string $format
  *
  * @return DateTime|null in site's time zone
  */
 public function get_datetime_with_timezone($datetime_string, $format = 'c')
 {
     static $utc_timezone, $local_timezone;
     if (!isset($utc_timezone)) {
         $utc_timezone = new DateTimeZone('UTC');
         $local_timezone = new DateTimeZone($this->get_timezone_string());
     }
     if (!empty($datetime_string) && YMBESEO_Utils::is_valid_datetime($datetime_string)) {
         $datetime = new DateTime($datetime_string, $utc_timezone);
         $datetime->setTimezone($local_timezone);
         return $datetime->format($format);
     }
     return null;
 }