java获取当前日期前一天和后一天

/** 
* 获得指定日期的前一天 
* @param specifiedDay 
* @return 
* @throws Exception 
*/ 
public static String getSpecifiedDayBefore(String specifiedDay){ 
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 
String cDate = df.format(new Date());
Calendar c = Calendar.getInstance(); 
Date date=null; 
try { 
date = new SimpleDateFormat("yy-MM-dd").parse(cDate); 
} catch (ParseException e) { 
e.printStackTrace(); 
} 
c.setTime(date); 
int day=c.get(Calendar.DATE); 
c.set(Calendar.DATE,day-1); 

String dayBefore=new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); 
return dayBefore; 
} 
/** 
* 获得指定日期的后一天 
* @param specifiedDay 
* @return 
*/ 
public static String getSpecifiedDayAfter(String specifiedDay){ 
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 
String cDate = df.format(new Date());
Calendar c = Calendar.getInstance(); Date date=null; try { date = new SimpleDateFormat("yy-MM-dd").parse(cDate);
}
catch (ParseException e) { e.printStackTrace(); } c.setTime(date); int day=c.get(Calendar.DATE); c.set(Calendar.DATE,day+1); String dayAfter=new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); return dayAfter; }
展开阅读全文

没有更多推荐了,返回首页