라이브러리
[PHP] MongoDBBSONTimestampInterface::getTimestamp - 이 TimestampInterface의 타임스탬프 구성 요소를 반환합니다.
MongoDBBSONTimestampInterface::getTimestamp
`MongoDBBSONTimestampInterface::getTimestamp`은 MongoDB에서 사용하는 BSON 타임스탬프를 반환하는 인터페이스 메소드입니다. 이 메소드는 BSON 타임스탬프를 64비트 정수 값으로 반환하며, 이는 Unix 시간 (1970-01-01 00:00:00 UTC) 이후 경과한 밀리초 수를 나타냅니다.
사용 예제
#hostingforum.kr
php
use MongoDBBSONTimestamp;
// Timestamp 객체 생성
$timestamp = new Timestamp(1643723400, 1);
// getTimestamp 메소드 호출
$timestampValue = $timestamp->getTimestamp();
echo "BSON 타임스탬프 값: $timestampValue
";
// Timestamp 객체가 64비트 정수 값을 반환함을 확인
var_dump($timestampValue);
출력 결과
#hostingforum.kr
BSON 타임스탬프 값: 1643723400000000001
int(1643723400000000001)
Timestamp 객체 생성
Timestamp 객체는 `MongoDBBSONTimestamp` 클래스를 사용하여 생성할 수 있습니다. 이 클래스에는 두 개의 생성자 메소드가 있습니다.
* `Timestamp(int $timestamp, int $inc)` : Timestamp 객체를 생성합니다. `$timestamp`는 Unix 시간 (1970-01-01 00:00:00 UTC) 이후 경과한 밀리초 수를 나타내며, `$inc`는 타임스탬프의 인크래멘트 값을 나타냅니다.
* `Timestamp(array $data)` : Timestamp 객체를 생성합니다. `$data`는 배열 형태의 데이터를 나타내며, `timestamp` 키와 `inc` 키가 포함되어야 합니다.
Timestamp 객체 메소드
Timestamp 객체에는 다음과 같은 메소드가 있습니다.
* `getTimestamp()`: Timestamp 객체의 64비트 정수 값을 반환합니다.
* `getTimestampValue()`: Timestamp 객체의 64비트 정수 값을 반환합니다. (이 메소드는 `getTimestamp()` 메소드와 동일합니다.)
* `getInc()`: Timestamp 객체의 인크래멘트 값을 반환합니다.
* `setTimestamp(int $timestamp)`: Timestamp 객체의 타임스탬프 값을 설정합니다.
* `setInc(int $inc)`: Timestamp 객체의 인크래멘트 값을 설정합니다.
Timestamp 객체 사용 예제
#hostingforum.kr
php
use MongoDBBSONTimestamp;
// Timestamp 객체 생성
$timestamp = new Timestamp(1643723400, 1);
// getTimestamp 메소드 호출
$timestampValue = $timestamp->getTimestamp();
echo "BSON 타임스탬프 값: $timestampValue
";
// getInc 메소드 호출
$incValue = $timestamp->getInc();
echo "인크래멘트 값: $incValue
";
// setTimestamp 메소드 호출
$timestamp->setTimestamp(1643723401);
// getTimestamp 메소드 호출
$updatedTimestampValue = $timestamp->getTimestamp();
echo "업데이트된 BSON 타임스탬프 값: $updatedTimestampValue
";
// setInc 메소드 호출
$timestamp->setInc(2);
// getInc 메소드 호출
$updatedIncValue = $timestamp->getInc();
echo "업데이트된 인크래멘트 값: $updatedIncValue
";
출력 결과
#hostingforum.kr
BSON 타임스탬프 값: 1643723400000000001
인크래멘트 값: 1
업데이트된 BSON 타임스탬프 값: 1643723401000000001
업데이트된 인크래멘트 값: 2
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.