java operation time, subtract one year, one day, one month from the current time

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    

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326804340&siteId=291194637