Js Date object to python datetime

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 provided start from the second line below:

end_date: Sat Nov 19 2011 01:00:00 GMT-0500 (EST) __proto__: Invalid Date constructor: function Date() { [native code] } getDate: function getDate() { [native code] } getDay: function getDay() { [native code] } getFullYear: function getFullYear() { [native code] } getHours: function getHours() { [native code] } getMilliseconds: function getMilliseconds() { [native code] } getMinutes: function getMinutes() { [native code] } getMonth: function getMonth() { [native code] } getSeconds: function getSeconds() { [native code] } getTime: function getTime() { [native code] } getTimezoneOffset: function getTimezoneOffset() { [native code] } getUTCDate: function getUTCDate() { [native code] } getUTCDay: function getUTCDay() { [native code] } getUTCFullYear: function getUTCFullYear() { [native code] } getUTCHours: function getUTCHours() { [native code] } getUTCMilliseconds: function getUTCMilliseconds() { [native code] } getUTCMinutes: function getUTCMinutes() { [native code] } getUTCMonth: function getUTCMonth() { [native code] } getUTCSeconds: function getUTCSeconds() { [native code] } getYear: function getYear() { [native code] } setDate: function setDate() { [native code] } setFullYear: function setFullYear() { [native code] } setHours: function setHours() { [native code] } setMilliseconds: function setMilliseconds() { [native code] } setMinutes: function setMinutes() { [native code] } setMonth: function setMonth() { [native code] } setSeconds: function setSeconds() { [native code] } setTime: function setTime() { [native code] } setUTCDate: function setUTCDate() { [native code] } setUTCFullYear: function setUTCFullYear() { [native code] } setUTCHours: function setUTCHours() { [native code] } setUTCMilliseconds: function setUTCMilliseconds() { [native code] } setUTCMinutes: function setUTCMinutes() { [native code] } setUTCMonth: function setUTCMonth() { [native code] } setUTCSeconds: function setUTCSeconds() { [native code] } setYear: function setYear() { [native code] } toDateString: function toDateString() { [native code] } toGMTString: function toGMTString() { [native code] } toISOString: function toISOString() { [native code] } toJSON: function toJSON() { [native code] } toLocaleDateString: function toLocaleDateString() { [native code] } toLocaleString: function toLocaleString() { [native code] } toLocaleTimeString: function toLocaleTimeString() { [native code] } toString: function toString() { [native code] } toTimeString: function toTimeString() { [native code] } toUTCString: function toUTCString() { [native code] } valueOf: function valueOf() { [native code] } __proto__: Object

What is the easiest method for choosing one of these toString methods and then parsing it on the python server side using datetime.strptime() to create a python datetime object?

The simple toString method returns me a datetime in the format:

Sat Nov 19 2011 00:00:00 GMT-0500 (EST)

Trying the different format directives proves unsuccessful.


datetime.strptime("Sat Nov 19 2011 00:00:00 GMT-0500 (EST)", "%a %b %d %Y %H:%M:%S %Z") ---> unconverted data remains: -0500 (EST)


datetime.strptime("Sat Nov 19 2011 00:00:00 GMT-0500 (EST)", "%a %b %d %Y %H:%M:%S %z") ---> ValueError: 'z' is a bad directive in format '%a %b %d %Y %H:%M:%S %z'

-------------Problems Reply------------

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 getUTCMilliseconds method to obtain a timestamp. It should return something like 1321463229215, which is just a timestamp.

Then, it's as easy as this:


Category:javascript Views:1 Time:2011-11-16

Related post

  • How do you add "3 months" to a datetime.date object in python? 2012-03-07

    Python date calculations, where art thou? I have a python app that needs to plot out dates every three months for several years. It's important that the dates occur exactly 4 times a year, and that the dates occur on the same day each year as much as

  • String date to date object in python 2011-10-31

    Possible Duplicate: Parsing Dates and Times from Strings using python I'm reading a string "2011-06-11" How can I cast this to a date object? thanks --------------Solutions------------- If you know it will be in that format, you can use the strptime

  • What is the best way to convert a zope DateTime object into Python datetime object? 2010-04-05

    I need to convert a zope 2 DateTime object into a Python datetime object. What is the best way to do that? Thanks, Erika --------------Solutions------------- modernthingy = datetime.datetime.fromtimestamp(zopethingy.timeTime()) The datetime instance

  • How to remove unconverted data from a Python datetime object 2011-02-18

    I have a database of mostly correct datetimes but a few are broke like so: Sat Dec 22 12:34:08 PST 20102015 Without the invalid year, this was working for me: end_date = soup('tr')[4].contents[1].renderContents() end_date = time.strptime(end_date,"%a

  • Date object vs. DateTime object 2011-04-19

    I am currently looking at the msdn pages for the date and datetime object. I also have reflector opened up, and it looks like the date and datetime object just reference the Date structure. Why do we have two objects which reference the same structur

  • sort date objects in Python 2010-08-07

    I start out with date strings: from operator import itemgetter import datetime as DT # unsorted dates raw = (map(int, "2010-08-01".split("-")), map(int, "2010-03-25".split("-")), map(int, "2010-07-01".split("-"))) transactions = [] for year, month, d

  • Python date string to date object 2010-05-10

    How do I convert a string to a date object in python? The string would be: "24052010" (corresponding to the format: "%d%m%Y") I don't want a datetime.datetime object, but rather a datetime.date --------------Solutions------------- You can use strptim

  • Convert a string to datetime object in python 2011-05-03

    I have a date string defined as followed: datestr = '2011-05-01' I want to convert this into a datetime object so i used the following code dateobj = datetime.datetime.strptime(datestr,'%Y-%m-%d') print dateobj But what gets printed is: 2011-05-01 00

  • Group together arbitrary date objects that are within a time range of each other 2010-08-07

    I want to split the calendar into two-week intervals starting at 2008-May-5, or any arbitrary starting point. So I start with several date objects: import datetime as DT raw = ("2010-08-01", "2010-06-25", "2010-07-01", "2010-07-08") transactions = [(

  • How do I get datetime from date object python? 2010-01-01

    How do I get datetime from date object python? I think of import datetime as dt today = dt.date.today() date_time = dt.datetime(today.year, today.month, today.day) Any easier solution? --------------Solutions------------- There are a few ways to do t

  • Easiest way to combine date and time strings to single datetime object using Python 2012-03-06

    I have a web form which has 2 input fields, "StartDate" and "StartTime". I convert the StartDate field's string into a Python datetime object, no problem. The StartTime field is passed in as a string in the form "0130" for 1:30am. What is the best wa

  • How do I translate a ISO 8601 datetime string into a Python datetime object? 2009-06-09

    This question already has an answer here: How to parse ISO formatted date in python? 11 answers I'm getting a datetime string in a format like "2009-05-28T16:15:00" (this is ISO 8601, I believe) one hack-ish option seems to be to parse the string usi

  • Inserting a python datetime.datetime object into mysql 2009-07-16

    I have a date column in a mysql table. I want to insert a datetime.datetime() object into this column. What should i be using in the execute statement? I have tried: now = datetime.datetime(2009,5,5) cursor.execute("INSERT INTO table (name, id, datec

  • How do I find the time difference between two datetime objects in python? 2009-08-28

    How do I tell the time difference in minutes between two datetime objects? --------------Solutions------------- >>> import datetime >>> a = datetime.datetime.now() >>> b = datetime.datetime.now() >>> c = b - a date

  • How do you convert a python time.struct_time object into a datetime object? 2009-11-08

    How do you convert a python time.struct_time object into a datetime.datetime object? I have a library that provides the first one and a second library that wants the second one... --------------Solutions------------- Use time.mktime() to convert the

  • How to get the Python date object for last Wednesday 2010-03-04

    Using Python I would like to find the date object for last Wednesday. I can figure out where today is on the calendar using isocalendar, and determine whether or not we need to go back a week to get to the previous Wednesday. However, I can't figure

  • How should I check that a given argument is a datetime.date object? 2010-05-04

    I'm currently using an assert statement with isinstance. Because datetime is a subclass of date, I also need to check that it isn't an instance of datetime. Surely there's a better way? from datetime import date, datetime def some_func(arg): assert i

  • How can I convert a Python datetime object to UTC? 2010-07-25

    I have a python datetime object which I would like to convert to UTC. I am planning to output it in RFC 2822 format to put in an HTTP header, but I am not sure if that matters for this question. I found some information on this site about converting

  • Now to convert this strings to date time object in Python or django? 2010-10-12

    Now to convert this strings to date time object in Python or django? 2010-08-17T19:00:00Z 2010-08-17T18:30:00Z 2010-08-17T17:05:00Z 2010-08-17T14:30:00Z 2010-08-10T22:20:00Z 2010-08-10T21:20:00Z 2010-08-10T20:25:00Z 2010-08-10T19:30:00Z 2010-08-10T19

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.135 (s). 11 q(s)