比较日期的先后
java.util.Date nowdate=new java.util.Date(); String myString = "2008-09-08"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.CHINA); Date d = sdf.parse(myString); boolean flag = d.before(nowdate); if(flag) System.out.print("早于今天") else System.out.print("晚于今天")
日期的月份增加减少
String startDate =
"201301"
;
String endDate =
"201207"
;
SimpleDateFormat sdf =
new
SimpleDateFormat(
"yyyyMM"
);
Calendar cal = Calendar.getInstance();
cal.setTime(sdf.parse(startDate));
//减一个月就是-1
cal.add(Calendar.MONTH,
1
);
System.out.println(sdf.format(cal.getTime()));