在做手机端app时,iOS测试发现获取时间戳一直显示NAN;
最简单的方法分享给大家
**new Date(item.time.replace(/-/g, ‘/’)).getTime()**兼容Android和ios都能快速解决
我这里主要实现通过时间戳获取秒数,计算时间差,再进行数据格式化转化为时分秒(两种方法,差异不是很大)
formatSecondsStr(value) {
let result = parseInt(value)
let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result /
60 % 60));
let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
// console.log(h,m,s)
if (h !== '00') h = h;
if (m !== '00') m = m;
if (s !== '00') s = s;
let res={
h,m,s
}
// let res = '';
// if (h !== '00') res += `${h}小时`;
// if (m !== '00') res += `${m}分钟`;
// res += `${s}秒`;
return res;
},
`
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)