Python 3.x 将MongoDB bson.int64.int64转换回长数字(和日期时间)

Python 3.x 将MongoDB bson.int64.int64转换回长数字(和日期时间),python-3.x,pymongo,bson,Python 3.x,Pymongo,Bson,MongoDB中的数据是这样存储的,它可能是一个ISODate,但不是: "timestamp": { "$numberLong": "1599142085021078272" }, 在Python 3中,我检索数据并执行以下操作: testDateTimeStamp = doc['timestamp'] print ("testDateTimeStamp:", testDateTimeStamp, &qu

MongoDB中的数据是这样存储的,它可能是一个ISODate,但不是:

"timestamp": {
    "$numberLong": "1599142085021078272"
},
在Python 3中,我检索数据并执行以下操作:

testDateTimeStamp = doc['timestamp']
print ("testDateTimeStamp:", testDateTimeStamp, " type=", type(testDateTimeStamp))
rowDateTime = datetime1.datetime.fromtimestamp(testDateTimeStamp)
print命令似乎将其解开,并显示了这一点,但如何在代码中将其转换回datetime

testDateTimeStamp: 1599152715643496874  type= <class 'bson.int64.Int64'>
testDateTimeStamp:1599152715643496874类型=
然后它会得到一个错误:

OSError:[Errno 22]参数无效


这是我第一次尝试让它工作。如果有更好的办法,请告诉我。我确实记得早些时候我必须除法以消除纳秒

one_minute = datetime1.timedelta(minutes=1)
testDateTimeStamp = int(int(doc['timestamp']) / 1000000000)
print ("testDateTimeStamp:", testDateTimeStamp, " type=", type(testDateTimeStamp))
rowDateTime = datetime1.datetime.fromtimestamp(testDateTimeStamp)

1599142085021078272这是一个日期还是时间?这是一个时间,非常精确。你可以将它粘贴到这里:哇,这太好了!很高兴知道这个信息