增加日期时间

增加年:
Date addTime(int year) {
    Calendar cd = new GregorianCalendar();
    cd.setTime(new Date());
    cd.add(GregorianCalendar.YEAR, year);
    return cd.getTime();
}

增加月:
Date addTime(int month) {
    Calendar cd = new GregorianCalendar();
    cd.setTime(new Date());
    cd.add(GregorianCalendar.MONTH, month);
    return cd.getTime();
}

增加天数:
Date addTime(int day) {
    Calendar cd = new GregorianCalendar();
    cd.setTime(new Date());
    cd.add(GregorianCalendar.DAY_OF_MONTH, day);
    return cd.getTime();
}

 

posted @ 2019-05-22 11:23  y-xs  阅读(439)  评论(0编辑  收藏  举报