【问题标题】:How to store Current date and time in ISODATE format in mongodb php?如何在 mongodb php 中以 ISODATE 格式存储当前日期和时间?
【发布时间】:2012-09-06 08:02:45
【问题描述】:

我想将当前 GMT 日期和时间以 ISODate 格式存储在 mongodb 中。 与此类似

ISODate("2012-07-26T17:43:25.678Z") 

我想以上述格式将结果存储在 mongodb 中(它应该是一个 ISODate 对象)。使用php如何生成这样的格式?

【问题讨论】:

    标签: datetime time mongodb-php gmt isodate


    【解决方案1】:

    我认为 DateTime 适合 ISODate,但您可能还想考虑http://php.net/manual/en/datetime.setisodate.php

    【讨论】:

      【解决方案2】:

      使用 MongoDate:http://www.php.net/manual/en/class.mongodate.php

      本页示例:

      <?php
      
      // save a date to the database
      $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"));
      
      // find dates between 1/15/2010 and 1/30/2010
      $collection->find(array("ts" => array('$gt' => $start, '$lte' => $end)));
      
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-26
        • 2017-07-11
        • 1970-01-01
        • 1970-01-01
        • 2018-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多