django Datefield to Unix timestamp

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

    Another option:

    import time
    from django.utils import timezone
    
    naive_date = timezone.make_naive(mydate, timezone.get_current_timezone())
    print int(time.mktime(naive_date.timetuple()))
    

提交回复
热议问题