/**
* 获得指定日期的前一天
*
* @param specifiedDay flag flag 判断是前一天还是后一天
* @return
* @throws Exception
*/
public static String getSpecifiedDayBefore(String specifiedDay, String flag) {
Calendar c = Calendar.getInstance();
Date date = null;
try {
date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);
} catch (ParseException e) {
e.printStackTrace();
}
c.setTime(date);
int day = c.get(Calendar.DATE);
if ("前一天".equals(flag)) {
c.set(Calendar.DATE, day - 1);
} else if ("后一天".equals(flag)) {
c.set(Calendar.DATE, day + 1);
}
String dayBefore = new SimpleDateFormat("yyyy-MM-dd").format(c
.getTime());
return dayBefore;
}
java 获得指定日期的前一天代码收藏
最新推荐文章于 2024-10-01 09:29:45 发布