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


PHP QDateTime::GetTimeZone方法代码示例

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


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

示例1: __construct

 /**
  * Construct a QDateTime. Does a few things differently than the php version:
  * - Always stores timestamps in local or given timezone, so time extraction is easy
  * - Has settings to determine if you want a date only or time only type
  * - Will NOT throw exceptions. Errors simply result in a null datetime.
  *
  * @param null|integer|string|QDateTime|DateTime $mixValue
  * @param DateTimeZone                           $objTimeZone
  * @param int                                    $intType
  *
  * @throws QCallerException
  */
 public function __construct($mixValue = null, DateTimeZone $objTimeZone = null, $intType = QDateTime::UnknownType)
 {
     if ($mixValue instanceof QDateTime) {
         // Cloning from another QDateTime object
         if ($objTimeZone) {
             throw new QCallerException('QDateTime cloning cannot take in a DateTimeZone parameter');
         }
         parent::__construct($mixValue->format('Y-m-d H:i:s'), $mixValue->GetTimeZone());
         $this->blnDateNull = $mixValue->IsDateNull();
         $this->blnTimeNull = $mixValue->IsTimeNull();
         $this->ReinforceNullProperties();
     } else {
         if ($mixValue instanceof DateTime) {
             // Subclassing from a PHP DateTime object
             if ($objTimeZone) {
                 throw new QCallerException('QDateTime subclassing of a DateTime object cannot take in a DateTimeZone parameter');
             }
             parent::__construct($mixValue->format('Y-m-d H:i:s'), $mixValue->getTimezone());
             // By definition, a DateTime object doesn't have anything nulled
             $this->blnDateNull = false;
             $this->blnTimeNull = false;
         } else {
             if (!$mixValue) {
                 // Set to "null date"
                 // And Do Nothing Else -- Default Values are already set to Nulled out
                 parent::__construct('2000-01-01 00:00:00', $objTimeZone);
             } else {
                 if (strtolower($mixValue) == QDateTime::Now) {
                     // very common, so quickly deal with now string
                     parent::__construct('now', $objTimeZone);
                     $this->blnDateNull = false;
                     $this->blnTimeNull = false;
                 } else {
                     if (substr($mixValue, 0, 1) == '@') {
                         // unix timestamp. PHP superclass will always store ts in UTC. Our class will store in given timezone, or local tz
                         parent::__construct(date('Y-m-d H:i:s', substr($mixValue, 1)), $objTimeZone);
                         $this->blnDateNull = false;
                         $this->blnTimeNull = false;
                     } else {
                         // string relative date or time
                         if ($intTime = strtotime($mixValue)) {
                             // The documentation states that:
                             // The valid range of a timestamp is typically from
                             // Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.
                             // (These are the dates that correspond to the minimum and maximum values
                             // for a 32-bit signed integer).
                             //
                             // But experimentally, 0000-01-01 00:00:00 is the least date displayed correctly
                             if ($intTime < -62167241486) {
                                 // Set to "null date"
                                 // And Do Nothing Else -- Default Values are already set to Nulled out
                                 parent::__construct('2000-01-01 00:00:00', $objTimeZone);
                             } else {
                                 parent::__construct(date('Y-m-d H:i:s', $intTime), $objTimeZone);
                                 $this->blnDateNull = false;
                                 $this->blnTimeNull = false;
                             }
                         } else {
                             // error
                             parent::__construct();
                             $this->blnDateNull = true;
                             $this->blnTimeNull = true;
                         }
                     }
                 }
             }
         }
     }
     // User is requesting to force a particular type.
     switch ($intType) {
         case QDateTime::DateOnlyType:
             $this->blnTimeNull = true;
             $this->ReinforceNullProperties();
             return;
         case QDateTime::TimeOnlyType:
             $this->blnDateNull = true;
             $this->ReinforceNullProperties();
             return;
         case QDateTime::DateAndTimeType:
             // forcing both a date and time type to not be null
             $this->blnDateNull = false;
             $this->blnTimeNull = false;
             break;
         default:
             break;
     }
 }
开发者ID:vaibhav-kaushal,项目名称:qc-framework,代码行数:99,代码来源:QDateTime.class.php


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