import org.junit.Test;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

public class MonthCalculator {
    public static String getPreNMonth(Integer n){
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.roll(GregorianCalendar.MONTH,n);
        String s = new SimpleDateFormat("yyyy-MM-dd").format(gregorianCalendar.getTime());
        return s;
    }
    @Test
    public void testPreCalculator(){
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(gregorianCalendar.getTime());
        System.out.println("当前日期:"+currentDate);
        String preNMonth = getPreNMonth(6);
        System.out.println("往前推6个月:"+preNMonth);
    }
}