django 处理时间字段

json.dumps(log_list,default=utils.json_datetime_handler)

import time,hashlib,json
import models
from django.shortcuts import render,HttpResponse
from MadKing import settings

from django.core.exceptions import ObjectDoesNotExist
def json_date_handler(obj):
    if hasattr(obj, 'isoformat'):
        return obj.strftime("%Y-%m-%d")


def json_datetime_handler(obj):
    if hasattr(obj, 'isoformat'):
        return obj.strftime("%Y-%m-%d %H:%M:%S")

 

posted on 2016-06-01 17:53  zhaobin022  阅读(358)  评论(0编辑  收藏  举报