PHP Conference Japan 2024

MongoDB\BSON\UTCDateTime::toDateTimeImmutable

(mongodb >=1.20.0)

MongoDB\BSON\UTCDateTime::toDateTimeImmutable傳回此 UTCDateTime 的 DateTimeImmutable 表示法

說明

final public MongoDB\BSON\UTCDateTime::toDateTimeImmutable(): DateTimeImmutable

參數

此函式沒有參數。

傳回值

傳回此 UTCDateTime 的 DateTimeImmutable 表示法。傳回的 DateTimeImmutable 將使用 UTC 時區。

錯誤/例外

範例

範例 #1 MongoDB\BSON\UTCDatetime::toDateTimeImmutable() 範例

<?php

$utcdatetime
= new MongoDB\BSON\UTCDateTime(1416445411987);
$datetime = $utcdatetime->toDateTimeImmutable();
var_dump($datetime->format('r'));
var_dump($datetime->format('U.u'));
var_dump($datetime->getTimezone());

?>

上述範例的輸出會類似於

string(31) "Thu, 20 Nov 2014 01:03:31 +0000"
string(17) "1416445411.987000"
object(DateTimeZone)#3 (2) {
  ["timezone_type"]=>
  int(1)
  ["timezone"]=>
  string(6) "+00:00"
}

另請參閱

新增註解

使用者貢獻的註解

此頁面沒有使用者貢獻的註解。
To Top