public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.MONTH, 5);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
System.out.println(sdf.format(new Date()));
System.out.println(sdf.format(calendar.getTime()));
}
日期
升序排列:数据从低到高排列。
降序排列:数据从高到低排列。(多应用于学习成绩的排名)
升降序
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
时间格式化
Collections.sort(list1, new Comparator<Chat>() {
public int compare(Chat chat1,Chat chat2){
if(chat1.getAddtime().getTime()>chat2.getAddtime().getTime()){
return 1;
}
if(chat1.getAddtime().getTime()==chat2.getAddtime().getTime()){
return 0;
}
return -1;
}
} );
对集合进行排序