suoutsky / stepping-stone

bug dictionary
1 stars 0 forks source link

Javascript date is invalid on iOS #7

Open suoutsky opened 6 years ago

suoutsky commented 6 years ago

var d = new Date("2015-12-31 00:00:00"); console.log(d.getDate() + '. ' + d.getMonth() + ' ' + d.getFullYear(); Result for Android:

31.11 2015 Result on iOS:

NaN. NaN NaN

to fixed it: var dateString = "2015-12-31 00:00:00"; var d = new Date(dateString.replace(/-/g, '/'));

suoutsky commented 6 years ago

解决方案: var dateString = "2015-12-31 00:00:00"; var d = new Date(dateString.replace(/-/g, '/'));

suoutsky commented 6 years ago

详细文档:http://www.iamaddy.net/2015/02/ios-javascript-date/