【发布时间】:2018-12-21 09:05:35
【问题描述】:
我的代码如下所示:
from pymongo import MongoClient
client = MongoClient()
client = MongoClient('localhost', 27017)
db = client.local
collection = db.orderbook_update
orderbook = collection.find({}).sort('lastUpdated', pymongo.DESCENDING).limit(1)
for order in orderbook:
print(order['lastUpdated'])
我的输出是这样的:1538589898191.0
我想做的是将此输出的秒数设为零,我不知道该怎么做......有什么帮助吗?谢谢!
【问题讨论】:
-
1538589898191.0的“秒”是多少?那是时间戳吗? -
它确实是一个以毫秒为单位的 unix 时间戳
-
您的意思是要显示从“上次更新”到“现在”的持续时间,例如天、小时、分钟?
-
不,只需取 lastUpdated 值 (1538589898191.0 ) 并将秒数归零
-
顺便说一句,第一个
client = MongoClient()是多余的。
标签: python python-3.x time