Posts

Showing posts with the label json

About datetime module and JSON

import datetime import simplejson as json >> Encoder dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else None json.dumps(datetime.datetime.now(), default=dthandler) >> Decoder try: v = datetime.datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%f) except ValueError: try: v = datetime.datetime.strptime(v, '%Y-%m-%d').date() except ValueError: ..........