I’m retrieving data from a JSON feed using jQuery and as part of the feed I’m getting ‘datetime’ attributes like “2009-07-01 07:30:09”. I want to put this information into a javascript Date object for easy use but I don’t believe the Date object would recognize this kind of format if I simply plugged it into the constructor. Is there a function or maybe a clever trick I can use to quickly break down this format into something the Date object can recognize and use?
Share
The “date” attribute you are retrieving from that webservice is not a real
Date, as it is not a recognized date format.The easiest way to handle it as a Date object would be to replace the empty space with a “T”:
This is not the most correct, as it is not handling timezones, but in most cases will work.