ios中g(shù)etTime()的兼容性實(shí)例代碼
時(shí)間格式為:2017-12-12 12:00:00在蘋(píng)果上獲取時(shí)間戳有兼容性問(wèn)題
需要轉(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í)間過(guò)去了多久
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()的兼容性?xún)?nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
iOS實(shí)現(xiàn)循環(huán)滾動(dòng)公告欄
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)循環(huán)滾動(dòng)公告欄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-03-03
iOS 簡(jiǎn)約日歷控件EBCalendarView的實(shí)現(xiàn)代碼
本篇文章主要介紹了iOS 簡(jiǎn)約日歷控件EBCalendarView的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05
iOS學(xué)習(xí)教程之UIView中坐標(biāo)轉(zhuǎn)換詳解
這篇文章主要給大家介紹了關(guān)于iOS UIView中坐標(biāo)轉(zhuǎn)換的相關(guān)資料,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)跟著小編一起看看吧。2017-05-05
iOS應(yīng)用進(jìn)入后臺(tái)后計(jì)時(shí)器和位置更新停止問(wèn)題的解決辦法
這篇文章主要介紹了iOS應(yīng)用進(jìn)入后臺(tái)后計(jì)時(shí)器和位置更新停止問(wèn)題的解決辦法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03
iOS開(kāi)發(fā)之導(dǎo)航欄各種右滑返回失效的解決方法匯總
這篇文章主要給大家總結(jié)介紹了關(guān)于iOS開(kāi)發(fā)教程之導(dǎo)航欄各種右滑返回失效的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位iOS具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08

