1

I have a webpage that creates a date from a string. It works fine except for the iphone where I get invalid date.

I have read a small bit about IOS handling dates a little differnt but have not been able to see a fix.

I have opened the page in the stock browser and the latest release of Chrome and get the same error. Works on Android and PC.

dateString = "2013-08-06"
date = new Date(dateString);

I have tried this fix but same error

var arr = "2010-03-15 10:30:00".split(/[- :]/),
date = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]);
416E64726577
  • 2,214
  • 2
  • 23
  • 47
Keith Power
  • 13,891
  • 22
  • 66
  • 135
  • This seems to be a duplicate of [http://stackoverflow.com/questions/5324178/javascript-date-parsing-on-iphone][1] [1]: http://stackoverflow.com/questions/5324178/javascript-date-parsing-on-iphone – Shaunak Aug 06 '13 at 14:58
  • This one is more about Javascript in an app as opposed to just a webpage issue. The solutions may be different. – Keith Power Aug 06 '13 at 15:08

1 Answers1

5

I just had an issue like this yesterday, but with internet explorer. I found that using a cross-browser date library like moment.js helped alleviate the issue:

var date = "2013-03-15 10:30:00";
date = moment(date, "YYYY-MM-DD HH:mm:ss").toDate();

Its just a wrapper around the date object, so the toDate() function returns its date object. If you want to take advantage of the formatting options moment provides, just remove the toDate().

Los Frijoles
  • 4,771
  • 5
  • 30
  • 49