wpy小程序处理ios时间问题
微信小程序展示时间会出现NAN,原因是ios对-不处理:
处理方法百度有在newDate之前 replace(/-/g, ‘/’)
还可以直接判断是否为ios,然后统一处理
代码片
.
// 处理时间
const formatTime = date => {
date = new Date(date)
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
if (wx.getSystemInfoSync().platform == 'ios') {
return (
[year, month, day].map(formatNumber).join('/') +
' ' +
[hour, minute, second].map(formatNumber).join(':')
);
} else {
return (
[year, month, day].map(formatNumber).join('-') +
' ' +
[hour, minute, second].map(formatNumber).join(':')
);
}
const formatNumber = n => {
n = n.toString();
return n[1] ? n : '0' + n;
};
};
在其他页面时间统一处理
//后台不接收 / 字段统一处理 - 在需要处理的时间够添加
replace(/\//g, '-')