android 短信时间排序,仿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

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

//End:modified by sunjinbiao on 20120823 for bug[540]

return res.getString(R.string.yesterday);

}else{

return dayOfWeek;

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值