Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(dateFormat.format(DateUtils.truncate(date, Calendar.HOUR_OF_DAY)));
//2009-08-04 16:00:00
System.out.println(dateFormat.format(DateUtils.truncate(date, Calendar.MINUTE)));//2009-08-04 16:23:00
System.out.println(dateFormat.format(DateUtils.truncate(date, Calendar.SECOND))); //2009-08-04 16:23:14
System.out.println(dateFormat.format(DateUtils.truncate(date, Calendar.DAY_OF_MONTH)));
//2009-08-04 00:00:00
System.out.println(dateFormat.format(DateUtils.truncate(date, Calendar.MONTH))); //2009-08-01 00:00:00
System.out.println(dateFormat.format(DateUtils.truncate(date, Calendar.YEAR))); //2009-01-01 00:00:00
DateUtils.addSeconds(date,-1);减一秒,可与truncate合用