Java得到指定日期的时间

//得到指定日期(几天前/几天后)整数往后推,负数往前移动
private Date getAppointDay(int num) throws ParseException {
DateFormat dateFormat = new SimpleDateFormat();
String format = dateFormat.format(new Date());//格式化当前时间
Date resultDate = dateFormat.parse(format);
Calendar calendar = new GregorianCalendar();
calendar.setTime(resultDate);
calendar.add(calendar.DATE,num);//整数往后推,负数往前移动
return calendar.getTime(); //指定的日期
}
posted @ 2019-06-14 22:05  SoyWang  阅读(4289)  评论(0编辑  收藏  举报