當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DateTimeImmutable::__construct方法代碼示例

本文整理匯總了PHP中DateTimeImmutable::__construct方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateTimeImmutable::__construct方法的具體用法?PHP DateTimeImmutable::__construct怎麽用?PHP DateTimeImmutable::__construct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DateTimeImmutable的用法示例。


在下文中一共展示了DateTimeImmutable::__construct方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * @param string $dt
  * @param \DateTimeZone|null $tz
  */
 public function __construct($dt = 'now', $tz = null)
 {
     if (is_null($dt) || $dt === 'now') {
         $date = \DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''));
     } else {
         $date = new \DateTime($dt, $tz);
     }
     parent::__construct($date->format(self::FULL_ISO8601));
 }
開發者ID:staffim,項目名稱:datetime,代碼行數:13,代碼來源:DateTime.php

示例2: __construct

 /**
  * @see http://stackoverflow.com/questions/17909871/getting-date-format-m-d-y-his-u-from-milliseconds
  *
  * @todo Support microtimes on relative formats: http://us3.php.net/manual/en/datetime.formats.relative.php
  *
  * @param string        $time
  * @param \DateTimeZone $timezone
  */
 public function __construct($time = self::NOW, \DateTimeZone $timezone = null)
 {
     $microtime = '0';
     if ($time === self::NOW) {
         $microtime = microtime(true);
         $microtime = \sprintf('%06d', ($microtime - \floor($microtime)) * 1000000);
     }
     parent::__construct(\date('Y-m-d H:i:s.' . $microtime, strtotime($time)), $timezone);
 }
開發者ID:improvframework,項目名稱:datetime,代碼行數:17,代碼來源:DateTimeImmutable.php

示例3: __construct

 public function __construct($useMicroseconds, \DateTimeZone $timezone = null)
 {
     $date = 'now';
     if ($useMicroseconds) {
         // Circumvent DateTimeImmutable::createFromFormat() which always returns \DateTimeImmutable instead of `static`
         // @link https://bugs.php.net/bug.php?id=60302
         $timestamp = microtime(true);
         $microseconds = sprintf("%06d", ($timestamp - floor($timestamp)) * 1000000);
         $date = date('Y-m-d H:i:s.' . $microseconds, (int) $timestamp);
     }
     parent::__construct($date, $timezone);
     $this->useMicroseconds = $useMicroseconds;
 }
開發者ID:intelogie,項目名稱:monolog,代碼行數:13,代碼來源:DateTimeImmutable.php

示例4: __construct

 public function __construct($useMicroseconds, \DateTimeZone $timezone = null)
 {
     $this->useMicroseconds = $useMicroseconds;
     $date = 'now';
     if ($useMicroseconds) {
         $timestamp = microtime(true);
         // apply offset of the timezone as microtime() is always UTC
         if ($timezone && $timezone->getName() !== 'UTC') {
             $timestamp += (new \DateTime('now', $timezone))->getOffset();
         }
         // Circumvent DateTimeImmutable::createFromFormat() which always returns \DateTimeImmutable instead of `static`
         // @link https://bugs.php.net/bug.php?id=60302
         //
         // So we create a DateTime but then format it so we
         // can re-create one using the right class
         $dt = self::createFromFormat('U.u', sprintf('%.6F', $timestamp));
         $date = $dt->format('Y-m-d H:i:s.u');
     }
     parent::__construct($date, $timezone);
 }
開發者ID:earncef,項目名稱:monolog,代碼行數:20,代碼來源:DateTimeImmutable.php

示例5: __construct

 /**
  * @param string             $time
  * @param \DateTimeZone|null $timezone
  */
 public function __construct($time = "now", $timezone = NULL)
 {
     parent::__construct($time, $timezone);
 }
開發者ID:wscore,項目名稱:site,代碼行數:8,代碼來源:DateTime.php


注:本文中的DateTimeImmutable::__construct方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。