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


PHP Horde_Date::_supportedSpecs方法代码示例

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


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

示例1: __construct

 /**
  * Builds a new date object. If $date contains date parts, use them to
  * initialize the object.
  *
  * Recognized formats:
  * - arrays with keys 'year', 'month', 'mday', 'day'
  *   'hour', 'min', 'minute', 'sec'
  * - objects with properties 'year', 'month', 'mday', 'hour', 'min', 'sec'
  * - yyyy-mm-dd hh:mm:ss
  * - yyyymmddhhmmss
  * - yyyymmddThhmmssZ
  * - yyyymmdd (might conflict with unix timestamps between 31 Oct 1966 and
  *   03 Mar 1973)
  * - unix timestamps
  * - anything parsed by strtotime()/DateTime.
  *
  * @throws Horde_Date_Exception
  */
 public function __construct($date = null, $timezone = null)
 {
     if (!self::$_supportedSpecs) {
         self::$_supportedSpecs = self::$_defaultSpecs;
         if (function_exists('nl_langinfo')) {
             self::$_supportedSpecs .= 'bBpxX';
         }
     }
     if (func_num_args() > 2) {
         // Handle args in order: year month day hour min sec tz
         $this->_initializeFromArgs(func_get_args());
         return;
     }
     $this->_initializeTimezone($timezone);
     if (is_null($date)) {
         return;
     }
     if (is_string($date)) {
         $date = trim($date, '"');
     }
     if (is_object($date)) {
         $this->_initializeFromObject($date);
     } elseif (is_array($date)) {
         $this->_initializeFromArray($date);
     } elseif (preg_match('/^(\\d{4})-?(\\d{2})-?(\\d{2})T? ?(\\d{2}):?(\\d{2}):?(\\d{2})(?:\\.\\d+)?(Z?)$/', $date, $parts)) {
         $this->_year = (int) $parts[1];
         $this->_month = (int) $parts[2];
         $this->_mday = (int) $parts[3];
         $this->_hour = (int) $parts[4];
         $this->_min = (int) $parts[5];
         $this->_sec = (int) $parts[6];
         if ($parts[7]) {
             $this->_initializeTimezone('UTC');
         }
     } elseif (preg_match('/^(\\d{4})-?(\\d{2})-?(\\d{2})$/', $date, $parts) && $parts[2] > 0 && $parts[2] <= 12 && $parts[3] > 0 && $parts[3] <= 31) {
         $this->_year = (int) $parts[1];
         $this->_month = (int) $parts[2];
         $this->_mday = (int) $parts[3];
         $this->_hour = $this->_min = $this->_sec = 0;
     } elseif ((string) (int) $date == $date) {
         // Try as a timestamp.
         if ($this->_timezone) {
             $oldtimezone = date_default_timezone_get();
             date_default_timezone_set($this->_timezone);
         }
         $parts = @getdate($date);
         if ($parts) {
             $this->_year = $parts['year'];
             $this->_month = $parts['mon'];
             $this->_mday = $parts['mday'];
             $this->_hour = $parts['hours'];
             $this->_min = $parts['minutes'];
             $this->_sec = $parts['seconds'];
         }
         if ($this->_timezone) {
             date_default_timezone_set($oldtimezone);
         }
     } else {
         if (!empty($timezone)) {
             try {
                 $parsed = new DateTime($date, new DateTimeZone($timezone));
             } catch (Exception $e) {
                 throw new Horde_Date_Exception(sprintf(Horde_Date_Translation::t("Failed to parse time string (%s)"), $date));
             }
         } else {
             try {
                 $parsed = new DateTime($date);
             } catch (Exception $e) {
                 throw new Horde_Date_Exception(sprintf(Horde_Date_Translation::t("Failed to parse time string (%s)"), $date));
             }
             $parsed->setTimezone(new DateTimeZone(date_default_timezone_get()));
             $this->_initializeTimezone(date_default_timezone_get());
         }
         $this->_year = (int) $parsed->format('Y');
         $this->_month = (int) $parsed->format('m');
         $this->_mday = (int) $parsed->format('d');
         $this->_hour = (int) $parsed->format('H');
         $this->_min = (int) $parsed->format('i');
         $this->_sec = (int) $parsed->format('s');
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:99,代码来源:Date.php


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