my model
create = models.DateTimeField(auto_now_add=True)
how to get unix time from this field?
datetime.datetime.timestamp()
but I need int
Here create is a simple python datetime.datetime instance itself.
For python less than 2.x
You can do .
my_model = MyModel()
int(my_model.create.strftime('%s'))
For python 3.3+
You can just do
my_model = MyModel()
my_model.create.timestamp()
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.