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
toUTCString() gives:
"Tue, 22 Nov 2011 06:00:00 GMT"
And that's parsible with:
datetime.strptime("Tue, 22 Nov 2011 06:00:00 GMT", "%a, %d %b %Y %H:%M:%S %Z")
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)
Try using python-dateutil (pip install python-dateutil)
import dateutil.parser as dt
date_time_obj = dt.parse("Tue, 22 Nov 2011 06:00:00 GMT")
date_time_obj will be a datetime object