edit: please check the second answer, it has a much better solution
In python code, you can do this to convert a date or datetime to the Unix Epoch
import time
epoch = int(time.mktime(mydate.timetuple())*1000)
This doesn't work in a Django template though, so you need a custom filter, e.g:
import time
from django import template
register = template.Library()
@register.filter
def epoch(value):
try:
return int(time.mktime(value.timetuple())*1000)
except AttributeError:
return ''
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…