转化时间格式
Date date =new Date();
String time="HH:MM:SS";
SimpleDateFormat formater=new SimpleDateFormat(time);
String dateStr=formater.format(date);
System.out.println(dateStr);
SimpleDateFormat formater2=new SimpleDateFormat("yyyy/MM/dd");
String dateStr2=formater2.format(new Date());
System.out.println(dateStr2);
定时调度线程
Timer timer =new Timer();
TimerTask task =new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(new Date());
}
};
timer.schedule(task, 1000,2000);
//内部类的写法
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(new Date());
}
},1000,2000);
List排序
public class Test{
public static void main(String[] args) {
User user1 = new User();
user1.setName("a");
user1.setOrder(1);
User user2 = new User();
user2.setName("b");
user2.setOrder(2);
List<User> list = new ArrayList<User>();
list.add(user2);
list.add(user1);
Collections.sort(list,new Comparator<User>(){
public int compare(User arg0, User arg1) {
return arg0.getOrder().compareTo(arg1.getOrder());
}
});
for(User u : list){
System.out.println(u.getName());
}
}
}
return改为:
return就成倒序的了