微信小程序中获取时间戳IOS不兼容
new Date(“2017-06-16”) 在IOS会出现NAN的情况所以对于时间转换需要另行封装,解决方案如下
把“-”替换为“/”, 这样iOS就能够正常获取年月日
var strTime="2022-05-26T10:56:24"; //字符串日期格式
var date= new Date(strTime.replace(/-/g, "/").replace("T", " ")); //转换成Data();
console.log(date.getFullYear()) // 获取年份
console.log(date.getMonth()+1) // 获取月份
console.log(date.getDate()) // 获取日
1.小程序在ios端用时间2022-05-26的形式下new Date的值为null必须使用2021/4/23的形式 android上无影响
2.ios端new Date(2022-05-26T10:56:24)时的值也无法正确转换android端无影响,要转换成2022/05/26 10:56:24可转换成功