django Datefield to Unix timestamp

前端 未结 6 1382
天涯浪人
天涯浪人 2020-12-05 02:08

In a model I have a such field: mydate = models.DateField()

now a javascript graph function requires unix timestamp such as \"1196550000000\", how can I return the u

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 02:56

    And if you're not in the template layer, you can still use the same underlying django utils. Ex:

    from django.utils.dateformat import format
    print format(mymodel.mydatefield, 'U')
    

提交回复
热议问题