JSON decode datetime

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

  1. JSON encode ISO UTC datetime by japerk 3 years, 1 month ago
  2. isoutc template filter by japerk 3 years, 1 month ago
  3. timeto template filter by japerk 3 years, 1 month ago
  4. Custom model field to store dict object in database by rudyryk 2 years, 1 month ago
  5. Extend simplejson to understand closures, functors, generators and iterators by ElfSternberg 3 years ago

Comments

schinckel (on August 5, 2010):

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.

#

(Forgotten your password?)