
MongoDB\BSON\UTCDateTime 클래스는 jsonSerialize() 메소드를 지원하지 않습니다. 그러나 JSON 형식으로 serialize 하려면 다음과 같은 방법을 사용할 수 있습니다.
#hostingforum.kr
php
$utcDateTime = new MongoDBBSONUTCDateTime();
$json = json_encode($utcDateTime->toDateTime());
위 코드는 MongoDB\BSON\UTCDateTime 객체를 DateTime 객체로 변환한 후, JSON 형식으로 serialize합니다.
또는 MongoDB\BSON\UTCDateTime 객체를 JSON 형식으로 serialize하기 위해, MongoDB\BSON\UTCDateTime 객체를 문자열로 변환한 후, JSON 형식으로 serialize할 수 있습니다.
#hostingforum.kr
php
$utcDateTime = new MongoDBBSONUTCDateTime();
$json = json_encode($utcDateTime->toDateTime()->format('Y-m-d H:i:s'));
위 코드는 MongoDB\BSON\UTCDateTime 객체를 DateTime 객체로 변환한 후, format() 메소드를 사용하여 날짜와 시간을 문자열로 변환한 후, JSON 형식으로 serialize합니다.
2025-03-14 16:25