简体   繁体   中英

Convert DateField to unix timestamp in Django

如何在Django中将DateField()值转换为单位时间戳表示?

As the DateField() returns a native Python datetime.date instance, https://docs.python.org/2/library/datetime.html , it will be the same as converting a datetime.date object to a unix timestamp integer.. such as:

import time
import django.models as models

date = models.DateField()
unix_timestamp = int(time.mktime(date.timetuple()))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM