本文整理汇总了PHP中DateTimeImmutable::setTimestamp方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeImmutable::setTimestamp方法的具体用法?PHP DateTimeImmutable::setTimestamp怎么用?PHP DateTimeImmutable::setTimestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeImmutable
的用法示例。
在下文中一共展示了DateTimeImmutable::setTimestamp方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: craftDateTime
public static function craftDateTime($seconds, $microseconds = 0)
{
// Override \Doctrine\ODM\MongoDB\Types\DateType::craftDateTime to return a DateTimeImmutable object
// in the 'UTC' timezone instead the current PHP one (date_default_timezone_get())
$datetime = new \DateTimeImmutable();
$datetime->setTimezone(new \DateTimeZone('UTC'));
$datetime->setTimestamp($seconds);
if ($microseconds > 0) {
$datetime = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s.u', $datetime->format('Y-m-d H:i:s') . '.' . $microseconds, new \DateTimeZone('UTC'));
}
return $datetime;
}
示例2: getDate
private static function getDate(\DateTime $dateTime)
{
$dateTimeImmutible = new \DateTimeImmutable();
$dateTimeImmutible->setTimestamp($dateTime->getTimestamp());
return $dateTimeImmutible;
}
示例3: testSetTimestamp
public function testSetTimestamp()
{
$time = '2000-01-02T03:14:25';
$immutable = new DateTimeImmutable($time);
$control = new DateTimeImmutable($time);
$mutable = new DateTime($time);
$new = $immutable->setTimestamp(1272508903);
$mutable->setTimestamp(1272508903);
$this->assertNotSame($immutable, $new);
$this->assertSame($control->format(DateTime::RFC3339), $immutable->format(DateTime::RFC3339));
$this->assertSame($mutable->format(DateTime::RFC3339), $new->format(DateTime::RFC3339));
}