Java Timestamp addDaysToTimestamp(Timestamp timestamp, int numDays)

Here you can find the source of addDaysToTimestamp(Timestamp timestamp, int numDays)

Description

Adds the specified number of Days to the specified Date object To subtract the specified number of Days to the specified Date object, juz use a negative number Example: DateUtil.addDaysToDate(date, -5) == subtracting 5 days from the specified date.

License

Apache License

Parameter

Parameter Description
date Timestamp to be add
numDays Number of days to add

Return

date Added Date

Declaration


public static Timestamp addDaysToTimestamp(Timestamp timestamp, int numDays) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Timestamp;
import java.util.Calendar;

public class Main {
    /**/*  w  ww.  j  av  a 2  s  .co m*/
     * Adds the specified number of Days to the specified Date object
     * To subtract the specified number of Days to the specified Date object, juz use a negative number
     * Example: DateUtil.addDaysToDate(date, -5) ==  subtracting 5 days from the specified date.
     *
     * @param date Timestamp to be add
     * @param numDays Number of days to add
     *
     * @return date  Added Date
     */

    public static Timestamp addDaysToTimestamp(Timestamp timestamp, int numDays) {
        if (timestamp == null) {
            return null;
        }

        Calendar c = Calendar.getInstance();
        c.setTime(timestamp);
        c.add(Calendar.DATE, numDays);

        return new Timestamp(c.getTimeInMillis());

    }
}

Related

  1. add(Timestamp ts, int field, int amount)
  2. addDate(Timestamp date, String type, int into)
  3. addDays(Timestamp date, int days)
  4. addDays(Timestamp day, int offset)
  5. addDaysToTimestamp(Timestamp start, int days)
  6. addHours(Timestamp date, int numOfHours)
  7. addHoursToTimestamp(Timestamp start, int hours)
  8. addMilli(Timestamp nowDate, int period)
  9. addMonth(java.sql.Timestamp src, int val)