ios中g(shù)etTime()的兼容性實(shí)例代碼
時(shí)間格式為:2017-12-12 12:00:00在蘋果上獲取時(shí)間戳有兼容性問題
需要轉(zhuǎn)換成2017/12/12 12:00:00 才可以正確獲取到時(shí)間戳
let u = navigator.userAgent; //判斷瀏覽器型號(hào) 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); }
判斷時(shí)間過去了多久 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) +'小時(shí)前'; } else if(minC>=1){ result=''+ parseInt(minC) +'分鐘前'; }else{ result='剛剛'; } return result; },
到此這篇關(guān)于ios中g(shù)etTime()的兼容性實(shí)例代碼的文章就介紹到這了,更多相關(guān)getTime()的兼容性內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Python獲取抖音關(guān)注列表封號(hào)賬號(hào)的實(shí)現(xiàn)代碼2. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報(bào)錯(cuò)問題分析3. php網(wǎng)絡(luò)安全中命令執(zhí)行漏洞的產(chǎn)生及本質(zhì)探究4. 解決Python 進(jìn)程池Pool中一些坑5. php測試程序運(yùn)行速度和頁面執(zhí)行速度的代碼6. Python如何讀寫CSV文件7. 三個(gè)不常見的 HTML5 實(shí)用新特性簡介8. ajax請求添加自定義header參數(shù)代碼9. python利用os模塊編寫文件復(fù)制功能——copy()函數(shù)用法10. 無線標(biāo)記語言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)第1/2頁
