
MongoDBBSONTimestamp 클래스의 __toString() 함수를 사용하여 Timestamp 객체를 문자열로 변환할 때 오류가 발생하는 이유는 PHP의 내장 클래스인 Timestamp가 __toString() 함수를 오버라이딩하지 않았기 때문입니다.
따라서 Timestamp 객체를 문자열로 변환할 때는 MongoDBBSONTimestamp 클래스의 toDateTime() 함수를 사용하는 것이 좋습니다.
다음은 Timestamp 객체를 문자열로 변환하는 방법입니다.
#hostingforum.kr
php
$timestamp = new MongoDBBSONTimestamp(1643723400, 1);
$date = $timestamp->toDateTime();
echo $date->format('Y-m-d H:i:s');
위의 코드를 실행하면 Timestamp 객체를 문자열로 변환할 수 있습니다.
또한, Timestamp 객체를 문자열로 변환할 때는 MongoDBBSONTimestamp 클래스의 toDateTime() 함수를 사용하는 것이 좋습니다.
이 외에도 Timestamp 객체를 문자열로 변환할 때는 DateTime 클래스를 사용하는 방법도 있습니다.
#hostingforum.kr
php
$timestamp = new MongoDBBSONTimestamp(1643723400, 1);
$date = new DateTime('@' . $timestamp->getTime());
echo $date->format('Y-m-d H:i:s');
위의 코드를 실행하면 Timestamp 객체를 문자열로 변환할 수 있습니다.
이러한 방법을 사용하면 Timestamp 객체를 문자열로 변환할 수 있습니다.
2025-03-14 01:26