1 2 3 4 5 6 7 8 9 | import dateutil.parser
def decode_datetime(obj):
if 'datetime' not in obj:
return obj
dt = dateutil.parser.parse(obj['datetime'])
obj['datetime'] = dt
return obj
|
More like this
- JSON encode ISO UTC datetime by japerk 4 years, 2 months ago
- isoutc template filter by japerk 4 years, 2 months ago
- timeto template filter by japerk 4 years, 2 months ago
- Proper fixtures loading in south data migrations by JustDelight 3 months, 3 weeks ago
- FuzzyDateTimeField by japerk 4 years, 2 months ago
Comments
If you have datetime objects as "%Y-%m-%d %H:%M:%S", then you don't need to convert them. Django will allow for using these in queries, and saving to the database.
Same with date ("%Y-%m-%d") and time ("%H:%M:%S") objects.
#