实现代码如下:
import json
from datetime import date, datetime
def __default(obj):
if isinstance(obj, datetime):
return obj.strftime('%Y-%m-%dT%H:%M:%S')
elif isinstance(obj, date):
return obj.strftime('%Y-%m-%d')
else:
raise TypeError('%r is not JSON serializable' % obj)
print json.dumps({'d': datetime.now(), 'today': date.today(), 'x': 111},
default=__default)更多让python json encode datetime类型相关文章请关注PHP中文网!
Easily find JSON paths within JSON objects using our intuitive Json Path Finder
30
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号