Java Timestamp addMonth(java.sql.Timestamp src, int val)

Here you can find the source of addMonth(java.sql.Timestamp src, int val)

Description

addMonth - Returns the timestamp after adding certain amount of Month.

License

Open Source License

Parameter

Parameter Description
src Source timestamp.
val Number of months going to add, can be negative number.

Return

Timestamp after adding certain amount of months.

Declaration

public static java.sql.Timestamp addMonth(java.sql.Timestamp src, int val) 

Method Source Code

//package com.java2s;
/*/*from  w ww . j a va 2  s.  co  m*/
* @(#)Utility.java
*
* Copyright (c) 2003 DCIVision Ltd
* All rights reserved.
*
* This software is the confidential and proprietary information of DCIVision
* Ltd ("Confidential Information").  You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with DCIVision Ltd.
 */

public class Main {
    /**
     * addMonth - Returns the timestamp after adding certain amount of Month.
     *
     * @param   src Source timestamp.
     * @param   val Number of months going to add, can be negative number.
     * @return  Timestamp after adding certain amount of months.
     */
    public static java.sql.Timestamp addMonth(java.sql.Timestamp src, int val) {
        java.util.Calendar tmpCal = timestampToCalendar(src);
        if (tmpCal == null) {
            return (null);
        }
        tmpCal.add(java.util.Calendar.MONTH, val);
        return (calendarToTimestamp(tmpCal));
    }

    /**
     * Returns Calendar converted from Timestamp.
     *
     * @param   inTime Source timestamp which to be converted.
     * @return  Calendar object which converted from input.
     */
    public static java.util.Calendar timestampToCalendar(java.sql.Timestamp inTime) {
        if (inTime == null) {
            return (null);
        }
        java.util.Calendar cal = java.util.Calendar.getInstance();
        cal.setTime(inTime);
        return (cal);
    }

    /**
     * Returns Timestamp converted from Calendar.
     *
     * @param   inCal Source calendar which to be converted.
     * @return  Timestamp object which converted from input.
     */
    public static java.sql.Timestamp calendarToTimestamp(java.util.Calendar inCal) {
        if (inCal == null) {
            return (null);
        }
        java.sql.Timestamp time = new java.sql.Timestamp(inCal.getTime().getTime());
        return (time);
    }
}

Related

  1. addDaysToTimestamp(Timestamp start, int days)
  2. addDaysToTimestamp(Timestamp timestamp, int numDays)
  3. addHours(Timestamp date, int numOfHours)
  4. addHoursToTimestamp(Timestamp start, int hours)
  5. addMilli(Timestamp nowDate, int period)
  6. addMonths(Timestamp refDate, int nrOfMonthsToAdd)
  7. addTime(java.sql.Timestamp start, int year, int month, int day)
  8. adjustTimestamp(Timestamp stamp, int adjType, int adjQuantity, TimeZone timeZone, Locale locale)
  9. adjustTimestamp(Timestamp stamp, Integer adjType, Integer adjQuantity)