How can I convert from Datetime to Milliseconds in Django?
<p>I want to convert date (ex: 2016-09-20 22:00:00+00:00) to milliseconds. I will apply this block:</p>

<pre><code>def get_calendar_events(request):

    user = request.user
    taken_course = Course.objects.get_enrollments(user=user)

    homework_list = []
    for course in taken_course:
        homework_list = course.get_homeworks()

    data_l = []
    for homework in homework_list:

    data_l.append({
            "id": user.id,
            "title": homework.title,
            "class": "event-important",
            "start": homework.start_date,  # Milliseconds
            "end": homework.end_date  # Milliseconds
        })

    data = {
        "success": 1,
        "result": [data_l]
    }
    return JsonResponse(data, safe=False)
</code></pre>

<p>I need to edit "start" and "end" tags in data_l. Thank you.</p>

<p>In python 3, you can use <a href="https://docs.python.org/3/library/datetime.html?highlight=re#datetime.datetime.timestamp" rel="nofollow"><code>timestamp()</code></a> method to get the number seconds elapsed since Jan 1, 1970. </p>

<pre><code>import datetime
d=datetime.datetime.now()
print d.timestamp()
# 1474450000.164866
</code></pre>

<p>This is assuming the <code>homework.start_date</code> field is a <code>datetime</code> object.</p>

python json django database datetime