本文整理匯總了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));
}