微信小程序开发问题-ios的Date问题
来源:互联网 发布:telnet远程端口 编辑:程序博客网 时间:2024/06/05 00:41
微信小程序开发问题-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 = new Date(myTime.substr(0,10)+"T"+myTime.substr(11,8));
用哪个看你(手动斜眼)
阅读全文