django Datefield to Unix timestamp

前端 未结 6 1398
天涯浪人
天涯浪人 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:39

    I know another answer was accepted a while ago, but this question appears high on Google's search results, so I will add another answer.

    If you are working at the template level, you can use the U parameter to the date filter, e.g.:

    {{ mydate|date:"U" }}
    

    Note that it will be based upon the TIMEZONE in your settings.py.

提交回复
热议问题