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


PHP QDateTime::setTimezone方法代码示例

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


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

示例1: setTime

 /**
  * Sets the time portion to the given time. If a QDateTime is given, will use the time portion of that object.
  * Works around a problem in php that if you set the time across a daylight savings time boundary, the timezone
  * does not advance. This version will detect that and advance the timezone.
  *
  * @param int|QDateTime $mixValue
  * @param int|null $intMinute
  * @param int|null $intSecond
  * @return QDateTime
  */
 public function setTime($mixValue, $intMinute = null, $intSecond = null)
 {
     if ($mixValue instanceof QDateTime) {
         if ($mixValue->IsTimeNull()) {
             $this->blnTimeNull = true;
             $this->ReinforceNullProperties();
             return $this;
         }
         // normalize the timezones
         $tz = $this->getTimezone();
         if ($tz && in_array($tz->getName(), timezone_identifiers_list())) {
             // php limits you to ID only timezones here, so make sure we have one of those
             $mixValue->setTimezone($tz);
         }
         $intHour = $mixValue->Hour;
         $intMinute = $mixValue->Minute;
         $intSecond = $mixValue->Second;
     } else {
         $intHour = $mixValue;
     }
     // If HOUR or MINUTE is NULL...
     if (is_null($intHour) || is_null($intMinute)) {
         parent::setTime($intHour, $intMinute, $intSecond);
         $this->blnTimeNull = true;
         $this->ReinforceNullProperties();
         return $this;
     }
     $intHour = QType::Cast($intHour, QType::Integer);
     $intMinute = QType::Cast($intMinute, QType::Integer);
     $intSecond = QType::Cast($intSecond, QType::Integer);
     $this->blnTimeNull = false;
     /*
     			// Possible fix for a PHP problem. Can't reproduce, so leaving code here just in case it comes back.
     			// The problem is with setting times across dst barriers
     			if ($this->Hour == 0 && preg_match('/[0-9]+/', $this->getTimezone()->getName())) {
     				// fix a php problem with GMT and relative timezones
     				$s = 'PT' . $intHour . 'H' . $intMinute . 'M' . $intSecond . 'S';
     				$this->add (new DateInterval ($s));
     				// will continue and set again to make sure, because boundary crossing will change the time
     			}*/
     parent::setTime($intHour, $intMinute, $intSecond);
     return $this;
 }
开发者ID:vaibhav-kaushal,项目名称:qc-framework,代码行数:53,代码来源:QDateTime.class.php


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