仿iphone中短信以及通话记录的时间显示
时间:2020-10-16 12:37:08|栏目:Android代码|点击: 次
废话不多说,上代码
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使用VideoView播放本地视频和网络视频的方法
栏 目:Android代码
下一篇:Android 1.5 1.6 2.0 2.1 2.2 的区别详解
本文地址:http://www.codeinn.net/misctech/12168.html