Here you can find the source of addMonths(Timestamp refDate, int nrOfMonthsToAdd)
Parameter | Description |
---|---|
refDate | the original date |
nrOfMonthsToAdd | the number of months to add |
public static Timestamp addMonths(Timestamp refDate, int nrOfMonthsToAdd)
//package com.java2s; /*//from www .java 2s. co m * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, and the * EPL 1.0 (http://h2database.com/html/license.html). Initial Developer: H2 * Group Iso8601: Initial Developer: Robert Rathsack (firstName dot lastName at * gmx dot de) */ import java.sql.Timestamp; import java.util.Calendar; public class Main { /** * Adds the number of months to the date. If the resulting month's number of * days is less than the original's day-of-month, the resulting * day-of-months gets adjusted accordingly: <br> * 30.04.2007 - 2 months = 28.02.2007 * * @param refDate the original date * @param nrOfMonthsToAdd the number of months to add * @return the new timestamp */ public static Timestamp addMonths(Timestamp refDate, int nrOfMonthsToAdd) { Calendar calendar = Calendar.getInstance(); calendar.setTime(refDate); calendar.add(Calendar.MONTH, nrOfMonthsToAdd); Timestamp resultDate = new Timestamp(calendar.getTimeInMillis()); resultDate.setNanos(refDate.getNanos()); return resultDate; } }