鍍金池/ 問答/Python  數(shù)據(jù)庫/ Python3中時間轉(zhuǎn)換

Python3中時間轉(zhuǎn)換

MongoDB存儲的日期格式是2018-07-01T00:00:00Z

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

相關(guān)代碼

collection.find_one(
    {
        "regDate": 
        {
            "$gte":ISODate("2018-07-01T00:00:00Z"),"$lt":ISODate("2018-07-31T00:00:00Z")
        }
    }
)
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
NameError: name 'ISODate' is not defined
回答
編輯回答
純妹

按您的報錯提示,您可以看下這個解決方案

https://jira.mongodb.org/browse/PYTHON-704
2017年2月9日 03:27
編輯回答
菊外人

ISODate是mongo命令行里用的,python里可用datetime。

from datetime import datetime

collection.find_one(
    {
        "regDate": {
            "$gte": datetime(2018, 6, 1), "$lt": datetime(2018, 7, 31)
        }
    }
)
2017年6月8日 08:53