iOS不兼容js的日期转化为时间戳的问题
在做微信公众号开发时,遇到了一个问题,new Date('2020-10-21')转时间戳,安卓手机上访问时,能拿到时间戳,从而正确转换时间,而在ios上缺不能正常显示,显示的时间为:NaN-NaN1-NaN Invalid Date。
解决方法:IOS5中的Safari能正确解析new Date()那么必须写成格式 new Date('2020/10/21');
封装的方法如下: (不传获取当前的时间戳)
export function timestamp(time) {
if (time) {
var time = format('yyyy-MM-dd HH:mm:ss', time)
return new Date(time.replace(/-/g, '/')).getTime()
} else {
return new Date().getTime()
}
}
ios下动态改动h5页面title
export function changeDocTitle(title) {
document.title = title
var i = document.createElement('iframe')
i.src = '/src/1.png'
i.style.display = 'none'
i.onload = function() {
setTimeout(function() {
i.remove()
}, 0)
}
document.body.appendChild(i)
}
接口调用传参时josn格式转化为formData
export function getformData(obj) {
return Object.keys(obj).reduce((pre, cur) => {
pre.append(cur, obj[cur])
return pre
}, new FormData())
}