java获取某日期之前/之后一天的日期(实现代码)

时间:2022-12-27 13:57:09
String today="2015-11-26";//new Date()
SimpleDateFormat sdf = new SimpleDateFrmat("yyyy-DD-mm");

Calendar calendar = Calendar.getInstance();//获取日历实例
calendar.setTime(sdf.parse(today));

calendar.add(Calendar.DAY_OF_MONTH, 1); //设置为后一天
String tomorrow= sdf.format(calendar.getTime());//获得后一天

calendar.add(Calendar.DAY_OF_MONTH, -1); //设置为前一天
String yesterday= sdf.format(calendar.getTime());//获得前一天