欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ios中getTime()的兼容性实例代码

程序员文章站 2022-05-14 16:29:51
时间格式为:2017-12-12 12:00:00在苹果上获取时间戳有兼容性问题需要转换成2017/12/12 12:00:00 才可以正确获取到时间戳 let u = navigator.use...

时间格式为:2017-12-12 12:00:00在苹果上获取时间戳有兼容性问题

需要转换成2017/12/12 12:00:00 才可以正确获取到时间戳

   let u = navigator.useragent;  //判断浏览器型号
   let isandroid = u.indexof('android') > -1 || u.indexof('adr') > -1;  //android终端
   let isios = !!u.match(/\(i[^;]+;( u;)? cpu.+mac os x/); //ios终端
   if(isios){
    let time = new date((v[0].createtime).replace(/-/g,'/')).gettime();
     this.timeago=this.getdatediff(time);
   }else{
    let time = new date(v[0].createtime).gettime();
     this.timeago=this.getdatediff(time);
   }
判断时间过去了多久
  getdatediff(datetimestamp){
  let result;
  let minute = 1000 * 60;
  let hour = minute * 60;
  let day = hour * 24;
  let halfamonth = day * 15;
  let month = day * 30;
  let now = new date().gettime();
  let diffvalue = now - datetimestamp;
  if(diffvalue < 0){
   return;
  }
  let monthc =diffvalue/month;
  let weekc =diffvalue/(7*day);
  let dayc =diffvalue/day;
  let hourc =diffvalue/hour;
  let minc =diffvalue/minute;
  if(monthc>=1){
   if(monthc<=12)
    result="" + parseint(monthc) + "月前";
   else{
    result="" + parseint(monthc/12) + "年前";
   }
  }
  else if(weekc>=1){
   result="" + parseint(weekc) + "周前";
  }
  else if(dayc>=1){
   result=""+ parseint(dayc) +"天前";
  }
  else if(hourc>=1){
   result=""+ parseint(hourc) +"小时前";
  }
  else if(minc>=1){
   result=""+ parseint(minc) +"分钟前";
  }else{
   result="刚刚";
  }
  return result;
 },

到此这篇关于ios中gettime()的兼容性实例代码的文章就介绍到这了,更多相关gettime()的兼容性内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

相关标签: ios getTime()