About datetime module and JSON
import datetime
import simplejson as json
>> Encoder
dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) else Nonejson.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:
..........
Comments
Post a Comment