JS Create A Date Object from value passed via AJAX Call
<p>I have a Python script that returns me a calculated date time in XML format like below:</p>

<pre><code>&lt;prev&gt;&lt;date&gt;2012,07,16&lt;/date&gt;&lt;time&gt;22:00:00&lt;/time&gt;&lt;/prev&gt;
</code></pre>

<p>Though I can change the format but my issue is that when I try creating a JS date object using the value returned - I get 'Invalid date':</p>

<pre><code>$.ajax({
        async: false,
        type: "POST",
        url:  "/cgi-bin/prev_hour.py",
        success: function(xml)
        {
                pdate = $(xml).find('date').text();
                ptime = $(xml).find('time').text();
                //alert prints correct date time ex 2012-07-16 22:00:00
        },
        error:function(xhr,err,html)
        {
                alert("Failed\nreadyState: "+xhr.readyState+"\nstatus: "+xhr.status + "\nresponseText: "+xhr.responseText);
        }

var max_date = new Date("'" + pdate + ptime + "'");
alert(max_date);
</code></pre>

<p>I tried a couple of possibilities like Python script returning in various format:</p>

<pre><code>&lt;prev&gt;&lt;date&gt;2012/07/16 &lt;/date&gt;&lt;time&gt;22:00:00&lt;/time&gt;&lt;/prev&gt;
&lt;prev&gt;&lt;date&gt;2012,07,16 &lt;/date&gt;&lt;time&gt;22,00,00&lt;/time&gt;&lt;/prev&gt; 
</code></pre>

<p>But still I get invalid date when trying to create a JS date object?</p>

<p>Please let me know the correct way to implement it.</p>
