
MongoDBBSONUTCDateTime::toDateTimeImmutable 메서드는 MongoDB에서 UTC 시간을 DateTimeImmutable 객체로 변환하는 데 사용됩니다.
이 메서드는 MongoDBBSONUTCDateTime 객체에서 시간을 추출하여 DateTimeImmutable 객체로 반환합니다.
사용법은 다음과 같습니다.
#hostingforum.kr
php
$utcDateTime = new MongoDBBSONUTCDateTime();
$dateTimeImmutable = $utcDateTime->toDateTimeImmutable();
위 코드는 MongoDBBSONUTCDateTime 객체를 생성하고, toDateTimeImmutable 메서드를 사용하여 DateTimeImmutable 객체를 반환합니다.
또한, MongoDBBSONUTCDateTime 객체를 생성할 때 timestamp 값을 지정할 수 있습니다.
#hostingforum.kr
php
$timestamp = 1643723400; // 2022-02-01 12:30:00
$utcDateTime = new MongoDBBSONUTCDateTime($timestamp);
$dateTimeImmutable = $utcDateTime->toDateTimeImmutable();
위 코드는 timestamp 값을 사용하여 MongoDBBSONUTCDateTime 객체를 생성하고, toDateTimeImmutable 메서드를 사용하여 DateTimeImmutable 객체를 반환합니다.
이러한 메서드는 MongoDB에서 시간을 변환하는 데 사용할 수 있으며, DateTimeImmutable 객체를 반환하여 시간을 쉽게 다룰 수 있습니다.
2025-05-15 03:17