java中在获取的系统时间上推迟一周,一月,或者一年,或者一年半

推迟一周:

Calendar curr = Calendar.getInstance();
curr.set(Calendar.DAY_OF_MONTH,curr.get(Calendar.DAY_OF_MONTH)+7);
Date date=curr.getTime();

推迟一个月

Calendar curr = Calendar.getInstance();
curr.set(Calendar.MONTH,curr.get(Calendar.MONTH)+1);
Date date=curr.getTime();

推迟一年:

Calendar curr = Calendar.getInstance();
curr.set(Calendar.YEAR,curr.get(Calendar.YEAR)+1);
Date date=curr.getTime();

推迟一年半:(灵活应用,年数不能加1.5,所以换成月来计算)

Calendar curr = Calendar.getInstance();
curr.set(Calendar.MONTH,curr.get(Calendar.MONTH)+18);
Date date=curr.getTime();

//注意:提前就用加的就可以了!灵活一点,年数不能加1.5,所以可以换成月来计算

你可能感兴趣的:(201912)