获取日期前多少天或者后多少天的日期
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Cal_tommorrow { public static void main(String[] args) { Date date = new Date(); Date date2 = Cal_Days(date, -365); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); System.out.println(sdf.format(date2)); } /** * @param 参照日期 * @param 天数(之前为负数,之后为正数) * @return 参照日期之前或之后days的日期 */ public static Date Cal_Days(Date date, int days) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + days); return calendar.getTime(); } }