当前时间往前后推算
作者:互联网
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date nowDate = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(nowDate);
Date updateDate1 = calendar.getTime();
System.out.println("当前时间="+sdf.format(updateDate1));
calendar.set(Calendar.DATE, - 180);
Date updateDate4 = calendar.getTime();
System.out.println("往前推180天的时间="+sdf.format(updateDate4));
//calendar.setTime(updateDate4);
calendar.set(Calendar.DATE, + 3);
Date updateDate5 = calendar.getTime();
System.out.println("180往后推3天的时间="+sdf.format(updateDate5));
}
标签:updateDate4,getTime,推算,往前,sdf,当前,Date,calendar,Calendar 来源: https://www.cnblogs.com/fan3516/p/10490628.html