JSON encode ISO UTC datetime

1
2
3
4
5
6
7
import datetime
from dateutil import tz

def encode_datetime(obj):
	if isinstance(obj, datetime.datetime):
		return obj.astimezone(tz.tzutc()).strftime('%Y-%m-%dT%H:%M:%SZ')
	raise TypeError(repr(o) + " is not JSON serializable")

More like this

  1. isoutc template filter by japerk 4 years, 1 month ago
  2. JSON decode datetime by japerk 4 years, 1 month ago
  3. timeto template filter by japerk 4 years, 1 month ago
  4. ModelForm ExtJS JSON Encoder by tian 4 years, 4 months ago
  5. Django newforms ExtJS JSON Encoder by davidblewett 4 years, 11 months ago

Comments

(Forgotten your password?)