当前位置: 首页>>代码示例>>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;未经允许,请勿转载。