[root@yyjk report]#cat t2.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json
from pymongo import MongoClient
import time
import datetime
from bson.objectid import ObjectId
start_time = datetime.datetime
print start_time
print datetime.datetime.now()
start_time = datetime.datetime(2019, 4, 6, 16, 0, 0)
print start_time
def object_id_from_datetime(from_datetime=None):
''' According to the time manually generated an ObjectId '''
if not from_datetime:
from_datetime = datetime.datetime.now()
return ObjectId.from_datetime(generation_time=from_datetime)
start_timestamp = object_id_from_datetime(start_time)
print start_timestamp
[root@yyjk report]#python t2.py
<type 'datetime.datetime'>
2019-04-09 09:28:04.773773
2019-04-06 16:00:00
5ca8cd000000000000000000
[root@yyjk report]#date
2019年 04月 09日 星期二 09:28:05 CST
import json
from pymongo import MongoClient
import time
def id2time(object_id):
timeStamp = int(object_id[:8], 16)
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timeStamp))
import pymongo
import time
import datetime
from bson.objectid import ObjectId
def object_id_from_datetime(from_datetime=None):
''' According to the time manually generated an ObjectId '''
if not from_datetime:
from_datetime = datetime.datetime.now()
return ObjectId.from_datetime(generation_time=from_datetime)
print id2time('5ca8cd000000000000000000')
C:Python27python.exe C:/Users/Administrator/PycharmProjects/untitled/F5/to_id_time.py
2019-04-07 00:00:00
Process finished with exit code 0