Compatibility instance code of gettime() in IOS

Time:2021-7-16

The time format is: 12:00:00, December 12, 2017. There is a compatibility problem when obtaining the time stamp on apple

You need to convert to 2017 / 12 / 12 12:00:00 to get the time stamp correctly

let u = navigator.userAgent;  // Determine browser model
   let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;  // Android terminal
   let isiOS = !! u.match(/\(i[^;]+;(  U;)?  CPU.+Mac OS X/); // IOS terminal
   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);
   }
Judge how long time has passed
  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) + "before the month";
   else{
    Result = + parseInt (monthcg12) + "years ago";
   }
  }
  else if(weekC>=1){
   Result = + parseInt (weekc) + "before the week";
  }
  else if(dayC>=1){
   Result = + parseInt (dayc) + "days ago";
  }
  else if(hourC>=1){
   Result = + parseInt (hourc) + "hours ago";
  }
  else if(minC>=1){
   Result = + parseInt (MinC) + "minutes ago";
  }else{
   Result = just now;
  }
  return result;
 },

This article about the compatibility instance code of gettime() in IOS introduces it. For more compatibility content of gettime(), please search previous articles of developer or continue to browse the following related articles. I hope you can support developer more in the future!

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]