Java Timestamp addHours(Timestamp date, int numOfHours)

Here you can find the source of addHours(Timestamp date, int numOfHours)

Description

add Hours

License

Open Source License

Declaration

public static Timestamp addHours(Timestamp date, int numOfHours) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;

public class Main {
    public static Timestamp addHours(Timestamp date, int numOfHours) { //changed

        Long milliSecInAnHour = new Long(60 * 60 * 1000);
        Timestamp newTS = new Timestamp(date.getTime());
        long milliSecToAdd = milliSecInAnHour * numOfHours;
        long newTimeMilliSec = newTS.getTime();
        newTS.setTime(newTimeMilliSec + milliSecToAdd);
        return newTS;

    }/*from  w ww  . j av  a 2 s  . co  m*/
}

Related

  1. addDate(Timestamp date, String type, int into)
  2. addDays(Timestamp date, int days)
  3. addDays(Timestamp day, int offset)
  4. addDaysToTimestamp(Timestamp start, int days)
  5. addDaysToTimestamp(Timestamp timestamp, int numDays)
  6. addHoursToTimestamp(Timestamp start, int hours)
  7. addMilli(Timestamp nowDate, int period)
  8. addMonth(java.sql.Timestamp src, int val)
  9. addMonths(Timestamp refDate, int nrOfMonthsToAdd)