这几天在做微信登录时,判断过期时间,获取当前时间转时间戳时,apple手机不兼容时间里的-必须要转成/,才能转时间戳。
let nowtime = timestamp(new Date());
function timestamp(nowTime){
let y=nowTime.getFullYear();
let m=nowTime.getMonth()+1;
m=m<10?('0'+m):m;
let d=nowTime.getDate();
d=d<10?('0'+d):d;
let h=nowTime.getHours();
h=h<10?('0'+h):h;
var minute = nowTime.getMinutes();
var second = nowTime.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute;
second = second < 10 ? ('0' + second) : second;
let nowDate= y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
let timestamp = new Date(nowDate.replace(/-/g, '/'));//必须
return timestamp.getTime();
}