仿iphone中短信以及通話記錄的時(shí)間顯示
更新時(shí)間:2013年06月19日 10:03:50 作者:
本篇文章是對(duì)仿iphone中短信以及通話記錄的時(shí)間顯示進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
廢話不多說(shuō),上代碼
public String getRelativeTimeSpanStringForIphone(long time,long now){
SimpleDateFormat formatter = null;
Resources res = mContext.getResources();
formatter = new SimpleDateFormat("yy-MM-dd");
String yearMonthDay = formatter.format(time);
if(time>now){
return yearMonthDay;
}
formatter = new SimpleDateFormat("E");
String dayOfWeek = formatter.format(time);
formatter = new SimpleDateFormat("kk:mm");
String hourMinuOfTime = formatter.format(time);
formatter = new SimpleDateFormat("kk:mm:ss");
String hourMinuSecOfNow = formatter.format(now);
long millisecOfNow = getMillisecOfNow(hourMinuSecOfNow);
if((now-millisecOfNow<time)||(now-millisecOfNow==time)){
String timeOfCurrentDay = hourMinuOfTime;
String[] hourAndminute = timeOfCurrentDay.split(":");
int hour =Integer.parseInt(hourAndminute[0]);
ContentResolver cv = mContext.getContentResolver();
String strTimeFormat = android.provider.Settings.System.getString(cv,android.provider.Settings.System.TIME_12_24);
if(strTimeFormat!=null){
if(strTimeFormat.equals("12")){
if(hour>12){
return res.getString(R.string.pm)+hour%12+":"+hourAndminute[1];
}else{
return res.getString(R.string.am)+hour%12+":"+hourAndminute[1];
}
}else{
return hour%24+":"+hourAndminute[1];
}
}else{
return hour%24+":"+hourAndminute[1];
}
}else{
if(now-518400000l-millisecOfNow>time){
return yearMonthDay;
}else{
if(now-millisecOfNow-86400000l<time){
//End:modified by sunjinbiao on 20120823 for bug[540]
return res.getString(R.string.yesterday);
}else{
return dayOfWeek;
}
}
}
}
復(fù)制代碼 代碼如下:
public String getRelativeTimeSpanStringForIphone(long time,long now){
SimpleDateFormat formatter = null;
Resources res = mContext.getResources();
formatter = new SimpleDateFormat("yy-MM-dd");
String yearMonthDay = formatter.format(time);
if(time>now){
return yearMonthDay;
}
formatter = new SimpleDateFormat("E");
String dayOfWeek = formatter.format(time);
formatter = new SimpleDateFormat("kk:mm");
String hourMinuOfTime = formatter.format(time);
formatter = new SimpleDateFormat("kk:mm:ss");
String hourMinuSecOfNow = formatter.format(now);
long millisecOfNow = getMillisecOfNow(hourMinuSecOfNow);
if((now-millisecOfNow<time)||(now-millisecOfNow==time)){
String timeOfCurrentDay = hourMinuOfTime;
String[] hourAndminute = timeOfCurrentDay.split(":");
int hour =Integer.parseInt(hourAndminute[0]);
ContentResolver cv = mContext.getContentResolver();
String strTimeFormat = android.provider.Settings.System.getString(cv,android.provider.Settings.System.TIME_12_24);
if(strTimeFormat!=null){
if(strTimeFormat.equals("12")){
if(hour>12){
return res.getString(R.string.pm)+hour%12+":"+hourAndminute[1];
}else{
return res.getString(R.string.am)+hour%12+":"+hourAndminute[1];
}
}else{
return hour%24+":"+hourAndminute[1];
}
}else{
return hour%24+":"+hourAndminute[1];
}
}else{
if(now-518400000l-millisecOfNow>time){
return yearMonthDay;
}else{
if(now-millisecOfNow-86400000l<time){
//End:modified by sunjinbiao on 20120823 for bug[540]
return res.getString(R.string.yesterday);
}else{
return dayOfWeek;
}
}
}
}
您可能感興趣的文章:
- Android通話記錄備份實(shí)現(xiàn)代碼
- android 添加按(power鍵)電源鍵結(jié)束通話(掛斷電話)
- Android之聯(lián)系人PinnedHeaderListView使用介紹
- Android系統(tǒng)聯(lián)系人全特效實(shí)現(xiàn)(上)分組導(dǎo)航和擠壓動(dòng)畫(huà)(附源碼)
- android 加載本地聯(lián)系人實(shí)現(xiàn)方法
- Android根據(jù)電話號(hào)碼獲得聯(lián)系人頭像實(shí)例代碼
- Android仿微信聯(lián)系人按字母排序
- Android獲取手機(jī)通訊錄、sim卡聯(lián)系人及調(diào)用撥號(hào)界面方法
- android開(kāi)發(fā)教程之使用listview顯示qq聯(lián)系人列表
- Android獲取手機(jī)通話記錄的方法
相關(guān)文章
Android 修改系統(tǒng)關(guān)機(jī)動(dòng)畫(huà)的實(shí)現(xiàn)
這篇文章主要介紹了Android 修改系統(tǒng)關(guān)機(jī)動(dòng)畫(huà)的實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2016-10-10
如何利用Flutter實(shí)現(xiàn)酷狗流暢Tabbar效果
這篇文章主要給大家介紹了關(guān)于如何利用Flutter實(shí)現(xiàn)酷狗流暢Tabbar效果的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-02-02
Android使用ExpandableListView實(shí)現(xiàn)三層嵌套折疊菜單
這篇文章主要介紹了Android使用ExpandableListView實(shí)現(xiàn)三層嵌套折疊菜單,對(duì)布局感興趣的同學(xué)可以參考下2021-04-04
Android實(shí)現(xiàn)動(dòng)態(tài)曲線繪制
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)動(dòng)態(tài)曲線繪制,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06
Android 8.0中一些坑以及對(duì)應(yīng)的解決方法
這篇文章主要給大家介紹了關(guān)于Android 8.0中一些坑以及對(duì)應(yīng)的解決方法的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09
Glide實(shí)現(xiàn)加載圖片顯示進(jìn)度條效果
Glide作為安卓開(kāi)發(fā)常用的圖片加載庫(kù),有許多實(shí)用而且強(qiáng)大的功能,那么,下面這篇文章主要給大家介紹了利用Glide實(shí)現(xiàn)加載圖片顯示進(jìn)度條效果的相關(guān)資料,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下來(lái)一起看看吧。2017-05-05
Android使用Jni實(shí)現(xiàn)壓力鍋數(shù)據(jù)檢測(cè)效果示例
這篇文章主要介紹了Android使用Jni實(shí)現(xiàn)壓力鍋數(shù)據(jù)檢測(cè)效果,涉及Android結(jié)合Jni實(shí)現(xiàn)進(jìn)度條模擬壓力鍋數(shù)據(jù)監(jiān)測(cè)效果的相關(guān)操作技巧,需要的朋友可以參考下2017-12-12

