123456789101112131415161718192021 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- @author: Deepcold
- @file: json_dump_date.py
- @time: 2019/8/21 8:51
- """
- from datetime import date
- import json
- from datetime import datetime
- class JsonCustomEncoder(json.JSONEncoder):
- def default(self, value):
- if isinstance(value, datetime):
- return value.strftime('%Y-%m-%d %H:%M:%S')
- elif isinstance(value, date):
- return value.strftime('%Y-%m-%d')
- else:
- return json.JSONEncoder.default(self, value)
|