Ale*_*ich 4 python django datetime django-models unix-timestamp
我的模特
create = models.DateTimeField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)
如何从这个领域获得unix时间?
datetime.datetime.timestamp()
Run Code Online (Sandbox Code Playgroud)
但我需要 int
这里 create 是一个简单的 python datetime.datetime 实例本身。
对于小于 2.x 的 python
你可以做 。
my_model = MyModel()
int(my_model.create.strftime('%s'))
Run Code Online (Sandbox Code Playgroud)
对于python 3.3+
你可以做
my_model = MyModel()
my_model.create.timestamp()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4425 次 |
| 最近记录: |