当前位置: 首页>>代码示例>>PHP>>正文


PHP DateTime::getTimezone方法代码示例

本文整理汇总了PHP中DateTime::getTimezone方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::getTimezone方法的具体用法?PHP DateTime::getTimezone怎么用?PHP DateTime::getTimezone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTime的用法示例。


在下文中一共展示了DateTime::getTimezone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getChangeTime

 /**
  *
  * Possible bug was also detected: date_sunrise() seems to return date of the previous day:
  * https://bugs.php.net/bug.php?id=53148
  *
  * To avoid issues, only compare day agnostic formats:  $dt->format('Hi')
  *
  * @param \DateTime $dateTime
  * @param $method
  *
  * @return \DateTime
  */
 private function getChangeTime(\DateTime $dateTime, $method)
 {
     $location = $dateTime->getTimezone()->getLocation();
     $horizonShift = new \DateTime('now', $dateTime->getTimezone());
     $horizonShift->setTimestamp($method($dateTime->getTimestamp(), SUNFUNCS_RET_TIMESTAMP, $location['latitude'], $location['longitude'], ini_get("date.sunrise_zenith"), $dateTime->getOffset() / 3600));
     return $horizonShift;
 }
开发者ID:pierswarmers,项目名称:mandate,代码行数:19,代码来源:SunlightRuleBase.php

示例2: testSetTimezone

 /**
  *
  */
 public function testSetTimezone()
 {
     $dt = new DateTime('2013-03-08 10:00:00');
     $dt->setTimezone('Europe/Berlin');
     $this->assertEquals('2013-03-08 11:00:00', $dt->format('Y-m-d H:i:s'));
     $this->assertEquals('Europe/Berlin', $dt->getTimezone()->getName());
     $dt->setTimezone(new \DateTimeZone('Indian/Mahe'), true);
     $this->assertEquals('2013-03-08 11:00:00', $dt->format('Y-m-d H:i:s'));
     $this->assertEquals('Indian/Mahe', $dt->getTimezone()->getName());
     $dt->setTimezone(null);
     $this->assertEquals('UTC', $dt->getTimezone()->getName());
 }
开发者ID:phellow,项目名称:date,代码行数:15,代码来源:DateTimeTest.php

示例3: toString

 public function toString(\DateTime $pDateTime, $pDateTimeZone)
 {
     if ($pDateTimeZone->getName() == $pDateTime->getTimezone()->getName()) {
         return $pDateTime->format('c');
     } else {
         $lDateTimeZone = $pDateTime->getTimezone();
         $pDateTime->setTimezone($pDateTimeZone);
         $lDateTimeString = $pDateTime->format('c');
         $pDateTime->setTimezone($lDateTimeZone);
         return $lDateTimeString;
     }
     return $pDateTime->format('c');
 }
开发者ID:jeanphilippe-p,项目名称:ObjectManagerLib,代码行数:13,代码来源:DateTime.php

示例4: format

 /**
  * @param $format
  * @return bool|string
  */
 public function format($format)
 {
     // convert alias string
     if (in_array($format, array_keys($this->formats))) {
         $format = $this->formats[$format];
     }
     // if valid unix timestamp...
     if ($this->dateTime !== false) {
         return jDateTime::strftime($format, $this->dateTime->getTimestamp(), $this->dateTime->getTimezone());
     } else {
         return false;
     }
 }
开发者ID:morilog,项目名称:jalali,代码行数:17,代码来源:jDate.php

示例5: getDateformat

 /**
  * getDateformat
  * @param string $dateFormat
  * @param string $timeFormat
  * @param string $locale
  * @param string $timezone
  * @param string $format
  * @return string
  **/
 public function getDateformat($dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null)
 {
     $date = new \DateTime();
     $formatValues = array('none' => IntlDateFormatter::NONE, 'short' => IntlDateFormatter::SHORT, 'medium' => IntlDateFormatter::MEDIUM, 'long' => IntlDateFormatter::LONG, 'full' => IntlDateFormatter::FULL);
     $formatter = IntlDateFormatter::create($locale, $formatValues[$dateFormat], $formatValues[$timeFormat], $date->getTimezone()->getName(), IntlDateFormatter::GREGORIAN, $format);
     return strtoupper($formatter->getPattern());
 }
开发者ID:philippeaellig,项目名称:uikit-bundle,代码行数:16,代码来源:DateformatExtension.php

示例6: getTimezoneSelectOptions

 public static function getTimezoneSelectOptions()
 {
     $dateTimeObject = new \DateTime();
     $currentTimeZone = isset($_SESSION['config']) && !empty($_SESSION['config']['timezone']) ? $_SESSION['config']['timezone'] : $dateTimeObject->getTimezone()->getName();
     $timezoneSelectOptions = '';
     $timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC);
     $lastGroup = '';
     foreach ($timezones as $timezone) {
         $timezoneParts = explode('/', $timezone);
         $curGroup = $timezoneParts[0];
         if ($curGroup != $lastGroup) {
             if ($lastGroup != '') {
                 $timezoneSelectOptions .= '</optgroup>';
             }
             $timezoneSelectOptions .= '<optgroup label="' . addslashes($curGroup) . '">';
             $lastGroup = $curGroup;
         }
         if ($timezone == $currentTimeZone) {
             $selected = ' selected="selected"';
         } else {
             $selected = '';
         }
         $timezoneSelectOptions .= '<option' . $selected . ' value="' . addslashes($timezone) . '">' . htmlspecialchars($timezone) . '</option>';
     }
     return $timezoneSelectOptions;
 }
开发者ID:Umz,项目名称:ImpressPages,代码行数:26,代码来源:Helper.php

示例7: main

function main()
{
    $date = new DateTime("now");
    $date->setTimezone(new DateTimeZone('America/Los_Angeles'));
    $tz = $date->getTimezone();
    print $tz->getName() . "\n";
}
开发者ID:badlamer,项目名称:hhvm,代码行数:7,代码来源:ext.php

示例8: __construct

 /**
  * Returns new DateTime object
  * 
  * @param string|int|DateTime $_time
  * @param string|DateTimeZone $_timezone
  */
 public function __construct($_time = "now", $_timezone = NULL)
 {
     // allow to pass instanceof DateTime
     if ($_time instanceof DateTime) {
         if (!$_timezone) {
             $_timezone = $_time->getTimezone();
         } else {
             $_time = clone $_time;
             $_time->setTimezone($_timezone);
         }
         $time = $_time->format("Y-m-d H:i:s");
     } else {
         $time = is_numeric($_time) ? "@" . floor($_time) : $_time;
     }
     if ($_timezone) {
         if (!$_timezone instanceof DateTimeZone) {
             $_timezone = new DateTimeZone($_timezone);
         }
         parent::__construct($time, $_timezone);
     } else {
         parent::__construct($time);
     }
     // Normalize Timezonename, as sometimes +00:00 is taken
     if (is_numeric($_time)) {
         $this->setTimezone('UTC');
     }
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:33,代码来源:DateTime.php

示例9: parseDate

 /**
  * convert a string into the required date format for the database
  * important: returned date is in german local time (mez)!
  * @param $string String the given string
  * @return string|null
  */
 public function parseDate($string)
 {
     $localTime = new DateTime();
     $date = strtotime($string);
     // format yyyy-mm-ddThh:ii:ssZ
     if ('z' === strpos(strtolower($string), -1, 1)) {
         $string = strtolower($string);
         $string = str_replace('z', '', $string);
         $string = str_replace('t', ' ', $string);
         $date = new DateTime($string, DateTimeZone::UTC);
         $date->setTimezone($localTime->getTimezone());
         $date = $date->format('Y-m-d H:i:s');
     } else {
         if ($date) {
             $date = date('Y-m-d H:i:s', $date);
             $date = new DateTime($date);
             $date = $date->format('Y-m-d H:i:s');
         }
     }
     if ($date && date('Y-m-d H:i:s') > $date) {
         return $date;
     }
     // if the date can not be parsed or is in future return the current date
     return date('Y-m-d H:i:s');
 }
开发者ID:schaechinger,项目名称:feader,代码行数:31,代码来源:ParserAbstract.php

示例10: mm_countdown

/**
 * Build and return the Countdown component.
 *
 * @since   1.0.0
 *
 * @param   array  $args  The args.
 *
 * @return  string        The HTML.
 */
function mm_countdown($args)
{
    $component = 'mm-countdown';
    // Set our defaults and use them as needed.
    $defaults = array('date' => '', 'time' => '', 'timezone' => '');
    $args = wp_parse_args((array) $args, $defaults);
    // Get clean param values.
    $date = $args['date'];
    $time = $args['time'];
    $timezone = $args['timezone'];
    // Enqueue pre-registerd 3rd party countdown script.
    wp_enqueue_script('mm-jquery-countdown');
    // Get Mm classes.
    $mm_classes = apply_filters('mm_components_custom_classes', '', $component, $args);
    // Create new date object.
    $date_obj = new DateTime($date . ' ' . $time . ' ' . $timezone);
    $utc_date_ojb = new DateTime($date . ' ' . $time);
    // Get timezone offset.
    $timezone_offset = $date_obj->getTimezone()->getOffset($utc_date_ojb) / 3600;
    // Pass data to JS as data attributes.
    $year = $date_obj->format('Y');
    $month = $date_obj->format('n');
    $day = $date_obj->format('j');
    $hour = $date_obj->format('G');
    $minute = $date_obj->format('i');
    $second = $date_obj->format('s');
    return sprintf('<div class="%s" data-year="%s" data-month="%s" data-day="%s" data-hour="%s" data-minute="%s" data-second="%s" data-timezone-offset="%s"></div>', esc_attr($mm_classes), esc_attr($year), esc_attr($month), esc_attr($day), esc_attr($hour), esc_attr($minute), esc_attr($second), esc_attr($timezone_offset));
}
开发者ID:roosalles,项目名称:mm-components,代码行数:37,代码来源:countdown.php

示例11: LatestTweetsList

 public function LatestTweetsList($limit = '5')
 {
     $conf = SiteConfig::current_site_config();
     if (empty($conf->TwitterName) || empty($conf->TwitterConsumerKey) || empty($conf->TwitterConsumerSecret) || empty($conf->TwitterAccessToken) || empty($conf->TwitterAccessTokenSecret)) {
         return new ArrayList();
     }
     $cache = SS_Cache::factory('LatestTweets_cache');
     if (!($results = unserialize($cache->load(__FUNCTION__)))) {
         $results = new ArrayList();
         require_once dirname(__FILE__) . '/tmhOAuth/tmhOAuth.php';
         require_once dirname(__FILE__) . '/tmhOAuth/tmhUtilities.php';
         $tmhOAuth = new tmhOAuth(array('consumer_key' => $conf->TwitterConsumerKey, 'consumer_secret' => $conf->TwitterConsumerSecret, 'user_token' => $conf->TwitterAccessToken, 'user_secret' => $conf->TwitterAccessTokenSecret, 'curl_ssl_verifypeer' => false));
         $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array('screen_name' => $conf->TwitterName, 'count' => $limit));
         $tweets = $tmhOAuth->response['response'];
         $json = new JSONDataFormatter();
         if (($arr = $json->convertStringToArray($tweets)) && is_array($arr) && isset($arr[0]['text'])) {
             foreach ($arr as $tweet) {
                 try {
                     $here = new DateTime(SS_Datetime::now()->getValue());
                     $there = new DateTime($tweet['created_at']);
                     $there->setTimezone($here->getTimezone());
                     $date = $there->Format('Y-m-d H:i:s');
                 } catch (Exception $e) {
                     $date = 0;
                 }
                 $results->push(new ArrayData(array('Text' => nl2br(tmhUtilities::entify_with_options($tweet, array('target' => '_blank'))), 'Date' => SS_Datetime::create_field('SS_Datetime', $date))));
             }
         }
         $cache->save(serialize($results), __FUNCTION__);
     }
     return $results;
 }
开发者ID:unisolutions,项目名称:silverstripe-latesttweets,代码行数:32,代码来源:LaTw_Page_Controller_Extension.php

示例12: reverseTransform

 /**
  * {@inheritdoc}
  */
 public function reverseTransform($rfc3339)
 {
     if (!is_string($rfc3339)) {
         throw new TransformationFailedException('Expected a string.');
     }
     if ('' === $rfc3339) {
         return;
     }
     try {
         $dateTime = new \DateTime($rfc3339);
     } catch (\Exception $e) {
         throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
     }
     if ($this->outputTimezone !== $dateTime->getTimezone()->getName()) {
         try {
             $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
         } catch (\Exception $e) {
             throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
         }
     }
     if (preg_match('/(\\d{4})-(\\d{2})-(\\d{2})/', $rfc3339, $matches)) {
         if (!checkdate($matches[2], $matches[3], $matches[1])) {
             throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
         }
     }
     return $dateTime;
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:30,代码来源:DateTimeToRfc3339Transformer.php

示例13: castFromBuiltin

 public static function castFromBuiltin(\DateTime $dt)
 {
     $newCls = new static();
     $newCls->setTimestamp($dt->getTimestamp());
     $newCls->setTimezone($dt->getTimezone());
     return $newCls;
 }
开发者ID:gmo,项目名称:common,代码行数:7,代码来源:DateTime.php

示例14: doFormatObject

 /**
  * Implements what IntlDateFormatter::formatObject() is in PHP 5.5+
  *
  * @param \IntlCalendar|\DateTime $object
  * @param string|int|array|null $format
  * @param string|null $locale
  * @return string
  * @throws LocalizedException
  */
 protected function doFormatObject($object, $format = null, $locale = null)
 {
     $pattern = $dateFormat = $timeFormat = $calendar = null;
     if (is_array($format)) {
         list($dateFormat, $timeFormat) = $format;
     } elseif (is_numeric($format)) {
         $dateFormat = $format;
     } elseif (is_string($format) || null == $format) {
         $dateFormat = $timeFormat = \IntlDateFormatter::MEDIUM;
         $pattern = $format;
     } else {
         throw new LocalizedException(new Phrase('Format type is invalid'));
     }
     $timezone = $object->getTimezone();
     if ($object instanceof \IntlCalendar) {
         $timezone = $timezone->toDateTimeZone();
     }
     $timezone = $timezone->getName();
     if ($timezone === '+00:00') {
         $timezone = 'UTC';
     } elseif ($timezone[0] === '+' || $timezone[0] === '-') {
         // $timezone[0] is first symbol of string
         $timezone = 'GMT' . $timezone;
     }
     return (new \IntlDateFormatter($locale, $dateFormat, $timeFormat, $timezone, $calendar, $pattern))->format($object);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:35,代码来源:DateTimeFormatter.php

示例15: actionCheck

 public function actionCheck()
 {
     $dt = new \DateTime();
     echo 'Current date/time: ' . $dt->format('d-m-Y H:i:s');
     echo '<br />';
     echo 'Current timezone: ' . $dt->getTimezone()->getName();
 }
开发者ID:Andrewkha,项目名称:book,代码行数:7,代码来源:TestTimezoneController.php


注:本文中的DateTime::getTimezone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。