RBG IT
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('< %=LabelCut offTime.Cl ientID%>') .innerText ;
var ASPfutureDate = new Date(ASPDate);
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('<
var ASPfutureDate = new Date(ASPDate);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(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
http://www.w3schools.com/jsref/jsref_tolocalestring.asp
ASKER
Absolutely tremendous 5 mins all done, thanks guys!
PS: W3Schools is generally a poor reference.
Better references are
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
and https://msdn.microsoft.com/library/kecw102f%28v=vs.94%29.aspx
Better references are
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
and https://msdn.microsoft.com/library/kecw102f%28v=vs.94%29.aspx