When manipulating time in Java, we often encounter certain values within a period of time, or calculate the number of days between a period of time
Date date = new Date();//Get the current time
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.YEAR, -1);//The current time minus one year, that is, the time one year ago
calendar.add(Calendar.MONTH, -1);//The current time Go one month ago, that is, the time one month ago
calendar.getTime();//Get the time one year ago, or the time one month ago
Date date = new Date();//Get the current time
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.YEAR, -1);//The current time minus one year, that is, the time one year ago
calendar.add(Calendar.MONTH, -1);//The current time Go one month ago, that is, the time one month ago
calendar.getTime();//Get the time one year ago, or the time one month ago