仿iphone中短信以及通話記錄的時間顯示
更新時間:2013年06月19日 10:03:50 作者:
本篇文章是對仿iphone中短信以及通話記錄的時間顯示進行了詳細的分析介紹,需要的朋友參考下
廢話不多說,上代碼
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;
}
}
}
}
復制代碼 代碼如下:
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通話記錄備份實現代碼
- android 添加按(power鍵)電源鍵結束通話(掛斷電話)
- Android之聯(lián)系人PinnedHeaderListView使用介紹
- Android系統(tǒng)聯(lián)系人全特效實現(上)分組導航和擠壓動畫(附源碼)
- android 加載本地聯(lián)系人實現方法
- Android根據電話號碼獲得聯(lián)系人頭像實例代碼
- Android仿微信聯(lián)系人按字母排序
- Android獲取手機通訊錄、sim卡聯(lián)系人及調用撥號界面方法
- android開發(fā)教程之使用listview顯示qq聯(lián)系人列表
- Android獲取手機通話記錄的方法
相關文章
Android使用ExpandableListView實現三層嵌套折疊菜單
這篇文章主要介紹了Android使用ExpandableListView實現三層嵌套折疊菜單,對布局感興趣的同學可以參考下2021-04-04

