Created
October 18, 2016 18:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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