本文整理汇总了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));
}
示例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);
}
示例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;
}
示例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);
}
示例5: __construct
/**
* @param string $time
* @param \DateTimeZone|null $timezone
*/
public function __construct($time = "now", $timezone = NULL)
{
parent::__construct($time, $timezone);
}