微信小程序开发问题-ios的Date问题

微信小程序开发问题-ios的Date问题

开发小程序过程中,发现后台默认返回的 “2017-11-11 11:11:11”;格式不支持会直接返回null,ios要这种格式:”2014-09-25T13:24:00”,因为要计算时间差getTime(),所以对于返回null需要兼容,百度了很多地方


解:

1.方法转化

strToDate(dateObj){
      dateObj = dateObj.replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '').replace(/(-)/g, '/')
      dateObj = dateObj.slice(0, dateObj.indexOf("."))
     return new Date(dateObj)
    }

2.方法2

safari兼容写法

var safariTime =  "2017-04-28 23:59:59".replace(/\-/g, '/')

用哪个看你(手动斜眼)

猜你喜欢

转载自blog.csdn.net/cx091/article/details/78900491
今日推荐