久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

ios中getTime()的兼容性實例代碼

瀏覽:5日期:2022-09-17 10:56:11

時間格式為: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
相關文章:
主站蜘蛛池模板: 建宁县| 宝鸡市| 克拉玛依市| 乌拉特前旗| 六枝特区| 陵川县| 清徐县| 秦安县| 红河县| 曲周县| 汶川县| 弋阳县| 卢龙县| 大姚县| 江陵县| 台东县| 永州市| 曲麻莱县| 苍溪县| 桐乡市| 恩平市| 教育| 兴隆县| 金坛市| 岳阳县| 开阳县| 达尔| 思南县| 神木县| 航空| 镇安县| 汉沽区| 高雄市| 富裕县| 邯郸县| 会同县| 新源县| 巫溪县| 奉贤区| 道孚县| 冀州市|