Link to home
Start Free TrialLog in
Avatar of RBG IT
RBG ITFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Javascript new Date not working in IE (Invalid Date)

I have a script that works fine in chrome but cannot convert the date in IE and gives an invalid date error.
I know it is something to do with the way the date is formatted that IE doesn't like.

I am passsing this date in Chrome from a label on a page (2015-05-27 03:00:00 PM)

               var ASPDate = document.getElementById('<%=LabelCutoffTime.ClientID%>').innerText;

               var ASPfutureDate = new Date(ASPDate);

User generated image
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(no points please) I just want to +1 on the moment.js library.  Makes parsing a breeze.
Where are you getting 'PM' in the second example?  I can't find any support for AM/PM in javascript date functions.  http://www.w3schools.com/jsref/jsref_obj_date.asp  Except in "toLocaleString()".  Firefox and Chrome produce the same results but IE8 is different.
5/28/2015, 7:01:35 PM // Chrome and Firefox
Thursday, May 28, 2015 7:02:06 PM // IE8

Open in new window

http://www.w3schools.com/jsref/jsref_tolocalestring.asp
Avatar of RBG IT

ASKER

Absolutely tremendous 5 mins all done, thanks guys!