Java: Customize adding 1 month to the current date

后端 未结 3 1742
一个人的身影
一个人的身影 2021-01-20 07:15

I\'ve read around and basically I\'ve figured out that the Calendar object is capable of adding 1 month to a date specified by using something like:

Calendar         


        
3条回答
  •  伪装坚强ぢ
    2021-01-20 08:05

    Well for add 30 days you can do something like this:

    public static java.sql.Date sumarFechasDias(java.sql.Date fch, int days) {
        Calendar cal = new GregorianCalendar();
        cal.setTimeInMillis(fch.getTime());
        cal.add(Calendar.DATE, days);
        return new java.sql.Date(cal.getTimeInMillis());
    }
    

    if days=30, it will return your date with 30 days added.

提交回复
热议问题