日期格式化在移动端的问题

IOS5版本里面的Safari解释new Date('2013-10-21') 就不正确,在IOS5的Safari中返回的永远是"Invalid Date"

解决办法:把2013-10-21这种格式的,通过正则(data.replace(/-/g, '/'))转换成2013/10/21

例子;

1 dateFormat (data) {
2   let date1 = new Date(data.replace(/-/g, '/'))
3   let date2 = date1.getFullYear() + '-' + date1.getMonth() + '-' + date1.getDate()
4   return date2
5  }

 

posted @ 2018-09-19 15:01  zhaobao1830  阅读(371)  评论(0编辑  收藏  举报