json dumps
__author__ = 'zhaobin022' import json from datetime import datetime class JsonCustomEncoder(json.JSONEncoder): def default(self,field): if isinstance(field,datetime): return field.strftime('%Y-%m-%d %H:%M:%S') obj = {'d':datetime.now()} ds = json.dumps(obj,cls=JsonCustomEncoder) print(ds)
__author__ = 'zhaobin022'
import json
from datetime import datetime
class JsonCustomEncoder(json.JSONEncoder):
def default(self,field):
if isinstance(field,datetime):
return field.strftime('%Y-%m-%d %H:%M:%S')
obj = {'d':datetime.now()}
ds = json.dumps(obj,cls=JsonCustomEncoder)
print(ds)