Js Date object to python datetime

后端 未结 3 1099
情深已故
情深已故 2021-01-01 23:07

I am working with dhtmlxscheduler and I am sending dates to the django server for processing.

Dhtmlxscheduler provides me with the following date object, the methods

3条回答
  •  再見小時候
    2021-01-01 23:17

    It looks like you are getting something like an ordinary javascript Date object. In this case, the easiest method is probably to use the getTime method to obtain a timestamp. It should return something like 1321463229215, which is just a timestamp in milliseconds.

    datetime's fromtimestamp expects a timestamp in seconds, so just divide that timestamp by 1000.0 and you're good to go

    from datetime import datetime
    datetime.fromtimestamp(1321463229215 / 1000.0)
    

提交回复
热议问题