Java 日期处理

获取上个月最后一天
http://www.oschina.net/code/snippet_32903_15460
Calendar calendar = Calendar.getInstance(); 
int month = calendar.get(Calendar.MONTH);
calendar.set(Calendar.MONTH, month-1);
calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DAY_OF_MONTH));  
Date strDateTo = calendar.getTime();  
System.out.println(formatter.format(strDateTo));

//更简单的办法
calendar.set(Calendar.DAY_OF_MONTH, 1); 
calendar.add(Calendar.DATE, -1);

你可能感兴趣的:(java)