如何选择MongoDate?我有这样的代码:
<?php
$conn = new Mongo();
$db = $conn->selectDB('jam');
$dt = new DateTime(date('Y-m-d'), new DateTimeZone('UTC'));
$ts = $dt->getTimestamp();
$today = new MongoDate($ts);
$query = $db->test;
$query->insert(array("today"=>$today));
?>
这是插入MongoDate的代码,但我无法捕捉格式('Y-m-d')。这是我选择的代码:
<?php
$conn = new Mongo();
$db = $conn->selectDB('jam');
$dt = new DateTime(date('Y-m-d'), new DateTimeZone('UTC'));
$ts = $dt->getTimestamp();
$today = new MongoDate($ts);
$query = $db->tes;
$cursor = $query->find();
foreach($cursor as $id=>$b){
echo "<h2><a href='formlist2.php?id=".$id."'>".$b['today']."</h2>";
}
?>
但结果是:
0.00000000 1484352000
0.00000000 1484352000
0.00000000 1484352000