Skip to content

Instantly share code, notes, and snippets.

@krmaxwell
Created October 18, 2016 18:48
Show Gist options
  • Save krmaxwell/fbf6d5eb6ff3d018fe44155df6d7b1d4 to your computer and use it in GitHub Desktop.
Save krmaxwell/fbf6d5eb6ff3d018fe44155df6d7b1d4 to your computer and use it in GitHub Desktop.
Code to serialize datetime.datetime objects using ISO 8601. See http://stackoverflow.com/a/10721564/1569808
import datetime
import json
class DTEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
return obj.isoformat()
return json.JSONEncoder.default(self, obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment