java 日期处理相关
/**
*获取指定日期 前后指定天数的 日期
*
*/
public static String getNewDate(String sdate, int days) throws Exception { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date inputDate = dateFormat.parse(sdate); Calendar calendar = new GregorianCalendar(); calendar.setTime(inputDate); calendar.add(Calendar.DAY_OF_MONTH, days); return dateFormat.format(calendar.getTime()); } @Test public void testdate() throws Exception { System.out.println(DateUtil.getNewDate("2011-07-11", -1));//2011-07-10 System.out.println(DateUtil.getNewDate("2011-07-11", 1));//2011-07-12 }
不积跬步无以至千里