This article illustrates the way Python converts objectid in MongoDB to timestamps. Share to everyone for your reference. The specific analysis is as follows:
The first four bits of the _id field in MongoDB are the 16-bit timestamp, which makes it easy to extract the timestamp from the _id by using Python
def timestamp_from_objectid (objectid): Result
= 0
Try: Result
= Time.mktime (objectid.generation_ Time.timetuple ())
except: Pass return result
Call Method:
Print (Timestamp_from_objectid objectid (' 5217a543dd99a6d9e0f74702 '))
return: 1377252547.0
PS: Here again for you to recommend a local UNIX timestamp conversion tool, with a variety of languages (python/php/java/mysql, etc.) Unix timestamp operation methods:
Unix Timestamp (timestamp) conversion tool:Http://tools.jb51.net/code/unixtime
I hope this article will help you with your Python programming.