(PECL mongo >=0.8.1)
警告 このクラスを定義している拡張モジュールは非推奨です。 かわりに MongoDB 拡張モジュールを使うべきです。 このクラスの代替として、以下が使えます。
はじめに
データベースの日付オブジェクトを表します。日付をデータベースに保存したり、 日付を問い合わせたりするときにはこのクラスを使わなければなりません。 次のように使います。
例1 MongoDate による日付の保存
<?php// 日付をデータベースに保存します$collection->save(array("ts" => new MongoDate()));$start = new MongoDate(strtotime("2010-01-15 00:00:00"));$end = new MongoDate(strtotime("2010-01-30 00:00:00"));// 2010/1/15 から 2010/1/30 までの日付を検索します$collection->find(array("ts" => array('$gt' => $start, '$lte' => $end)));?>
MongoDB は、日付データをエポックからの経過ミリ秒数で格納します。 つまり、日付にはタイムゾーンの情報が 含まれないということです。 タイムゾーンが必要なら、別のフィールドを用意する必要があります。 また、データベースとの間でドキュメントをやりとりすると、 ミリ秒より細かい単位の情報は失われてしまいます。
クラス概要
MongoDate {
public
int
$sec
public
int
$usec
/* メソッド */
public __construct
([ int $sec
= time()
[, int $usec
= 0
]] )
public toDateTime ( ) : DateTime
public __toString ( ) : string
}
目次
- MongoDate::__construct — Creates a new date
- MongoDate::toDateTime — Returns a DateTime object representing this date
- MongoDate::__toString — Returns a string representation of this date
/* フィールド */