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]);
4

1 回答 1

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().

于 2013-08-06T15:00:52.383 回答