라이브러리
[PHP] MongoDBBSONUTCDateTime::toDateTimeImmutable - 이 UTCDateTime의 DateTimeImmutable 표현을 반환합니다.
MongoDBBSONUTCDateTime::toDateTimeImmutable
`MongoDBBSONUTCDateTime::toDateTimeImmutable`은 MongoDB의 BSON UTC DateTime 타입을 PHP의 DateTimeImmutable 타입으로 변환하는 메서드입니다. 이 메서드는 MongoDB의 BSON 데이터를 PHP의 DateTimeImmutable 객체로 변환하여 PHP에서 사용할 수 있도록 해줍니다.
사용 예제
#hostingforum.kr
php
use MongoDBBSONUTCDateTime;
use DateTimeImmutable;
// MongoDB의 BSON UTC DateTime 타입을 생성합니다.
$utcDateTime = new UTCDateTime();
// PHP의 DateTimeImmutable 타입으로 변환합니다.
$dateTimeImmutable = $utcDateTime->toDateTimeImmutable();
// 변환된 DateTimeImmutable 객체를 출력합니다.
echo $dateTimeImmutable->format('Y-m-d H:i:s') . "
";
// MongoDB의 BSON UTC DateTime 타입으로 변환합니다.
$utcDateTimeAgain = $dateTimeImmutable->getTimestamp();
// 변환된 UTC DateTime 타입을 출력합니다.
echo $utcDateTimeAgain . "
";
출력
#hostingforum.kr
2024-02-13 14:30:00
1676348400
사용 방법
1. `MongoDBBSONUTCDateTime` 클래스를 사용하여 MongoDB의 BSON UTC DateTime 타입을 생성합니다.
2. `toDateTimeImmutable` 메서드를 사용하여 PHP의 DateTimeImmutable 타입으로 변환합니다.
3. 변환된 DateTimeImmutable 객체를 사용하여 날짜 및 시간 정보를 가져올 수 있습니다.
4. `getTimestamp` 메서드를 사용하여 MongoDB의 BSON UTC DateTime 타입으로 변환할 수 있습니다.
주의
* `toDateTimeImmutable` 메서드는 MongoDB의 BSON UTC DateTime 타입을 PHP의 DateTimeImmutable 타입으로 변환합니다. 따라서 변환된 DateTimeImmutable 객체는 MongoDB의 BSON UTC DateTime 타입과 호환되지 않습니다.
* `getTimestamp` 메서드는 PHP의 DateTimeImmutable 타입을 MongoDB의 BSON UTC DateTime 타입으로 변환합니다. 따라서 변환된 UTC DateTime 타입은 MongoDB의 BSON UTC DateTime 타입과 호환됩니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.