仿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使用BottomTabBar实现底部导航页效果
这篇文章主要介绍了Android使用BottomTabBar实现底部导航页效果,本文通过实例代码结合文字说明的形式给大家介绍的非常详细,需要的朋友参考下吧2018-03-03Android自定义listview布局实现上拉加载下拉刷新功能
这篇文章主要介绍了Android自定义listview布局实现上拉加载下拉刷新功能,非常不错,具有参考借鉴价值,需要的朋友可以参考下2016-12-12Flutter利用SizeTransition实现组件飞入效果
本文将为大家介绍SizeTransition,SizeTransition用于更改子组件的尺寸来实现动画,支持垂直方向或水平方向修改动画。本文将利用其实现组件飞入效果,需要的可以参考一下2022-04-04Android 让自定义TextView的drawableLeft与文本一起居中
本文主要介绍Android 自定义控件TextView显示居中问题,在开发过程中经常会遇到控件的重写,这里主要介绍TextView的drawableLeft与文本一起居中的问题2016-07-07Android编程开发ScrollView中ViewPager无法正常滑动问题解决方法
这篇文章主要介绍了Android编程开发ScrollView中ViewPager无法正常滑动问题解决方法,以实例形式分析了ScrollView中滑动失效的原因及解决方法,具有一定参考借鉴价值,需要的朋友可以参考下2015-10-10
最新评论