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中文网!
查看更多关于让pythonjsonencodedatetime类型的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did82857
让pythonjsonencodedatetime类型
实现代码如下:
阅读:43次