Collections.sort排序

  Collections.sort(list, new Comparator<Notice>() {


@Override
public int compare(Notice lhs, Notice rhs) {
Long time1=Long.parseLong(OtherUtil.getTime(lhs.getIssue_datetime(), "yyyy-M-d HH:mm"));
Long time2=Long.parseLong(OtherUtil.getTime(rhs.getIssue_datetime(), "yyyy-M-d HH:mm"));
if( time1<time2){
return 1;
}else if( time1>time2){
return -1;
}
return 0;
}    

}); 


/**
* 将字符串转为时间戳
* @param user_time  例如:user_time = "2015-1-3 09:03"; 
* @param format  格式  例如: "yyyy-M-d HH:mm"; 
* @return
*/
public static String getTime(String user_time,String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date d;
if (isNull(user_time)) {
return "";
}
try {
d = sdf.parse(user_time);
long l = d.getTime();
return String.valueOf(l);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}





public static boolean isNull(String context) {
if ("".equals(context) || context == null) {
return true;
} else {
return false;
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值