java 日期计算加减
- 摘要:java计算日期加减publicstaticvoidmain(String[]args){StringlastConTime="2011-11-23";SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy-MM-dd");GregorianCalendarcalendar=newGregorianCalendar();try{DatedateTime=dateFormat.parse(lastConTime);calendar.setTime
- 标签:Java
java计算日期加减
public static void main(String[] args) {
String lastConTime = "2011-11-23";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar calendar = new GregorianCalendar();
try {
Date dateTime = dateFormat.parse(lastConTime);
calendar.setTime(dateTime);
calendar.add(calendar.DAY_OF_YEAR, 10);
Date lastTime = calendar.getTime();
String confirmTime = dateFormat.format(lastTime);
System.out.println(confirmTime);
} catch (ParseException e) {
e.printStackTrace();
}
}