Reputation: 7518
I am trying to convert the value of an <input type="date" />
to an actual Javascript Date object. The example is below
new Date($('#myInput').val()); //where value of myInput is '2011-01-01'
turns out to be
Fri Dec 31 2010 19:00:00 GMT-0500 (Eastern Standard Time)
It appears that the Date is convert from UTC to EST (I think). Is there anyway to prevent this conversion????
example: jsfiddle
Upvotes: 4
Views: 1453
Reputation: 324760
Try this:
ver date = new Date(document.getElementById('myinput').value);
date.setTime(date.getTime()+date.getTimezoneOffset()*60000);
Alternatively, use the getUTC*()
functions.
Upvotes: 0
Reputation: 3873
Use Date.prototype.toUTCString
to convert your locale-specific date to UTC
(new Date($('#myInput').val())).toUTCString()
Upvotes: 2