ios中getTime()的兼容性实例代码
时间格式为:2017-12-1212:00:00在苹果上获取时间戳有兼容性问题
需要转换成2017/12/1212:00:00才可以正确获取到时间戳
letu=navigator.userAgent;//判断浏览器型号
letisAndroid=u.indexOf('Android')>-1||u.indexOf('Adr')>-1;//android终端
letisiOS=!!u.match(/\(i[^;]+;(U;)?CPU.+MacOSX/);//ios终端
if(isiOS){
lettime=newDate((v[0].createTime).replace(/-/g,'/')).getTime();
this.timeago=this.getDateDiff(time);
}else{
lettime=newDate(v[0].createTime).getTime();
this.timeago=this.getDateDiff(time);
}
判断时间过去了多久
getDateDiff(dateTimeStamp){
letresult;
letminute=1000*60;
lethour=minute*60;
letday=hour*24;
lethalfamonth=day*15;
letmonth=day*30;
letnow=newDate().getTime();
letdiffValue=now-dateTimeStamp;
if(diffValue<0){
return;
}
letmonthC=diffValue/month;
letweekC=diffValue/(7*day);
letdayC=diffValue/day;
lethourC=diffValue/hour;
letminC=diffValue/minute;
if(monthC>=1){
if(monthC<=12)
result=""+parseInt(monthC)+"月前";
else{
result=""+parseInt(monthC/12)+"年前";
}
}
elseif(weekC>=1){
result=""+parseInt(weekC)+"周前";
}
elseif(dayC>=1){
result=""+parseInt(dayC)+"天前";
}
elseif(hourC>=1){
result=""+parseInt(hourC)+"小时前";
}
elseif(minC>=1){
result=""+parseInt(minC)+"分钟前";
}else{
result="刚刚";
}
returnresult;
},
到此这篇关于ios中getTime()的兼容性实例代码的文章就介绍到这了,更多相关getTime()的兼容性内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。