如何在Django中将DateField()
值转换为单位时间戳表示?
答案 0 :(得分:1)
当DateField()返回本机Python datetime.date实例https://docs.python.org/2/library/datetime.html时,它与将datetime.date对象转换为unix时间戳整数相同。例如:
import time
import django.models as models
date = models.DateField()
unix_timestamp = int(time.mktime(date.timetuple()))