活着就是恶心下载,乘风破浪会有时,想你的夜伴奏
时间格式为: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 使用UITextField自定义搜索框 实现用户输入完之后“实时搜索”功能
网友评论