Java Timestamp dateAdd(Timestamp t1, Integer i, int type)

Here you can find the source of dateAdd(Timestamp t1, Integer i, int type)

Description

date Add

License

Open Source License

Declaration

public static Timestamp dateAdd(Timestamp t1, Integer i, int type) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Timestamp;

public class Main {
    public static Timestamp dateAdd(Timestamp t1, Integer i, int type) {
        long interval = i * 1000 * 60 * 60 * 24l;
        Timestamp t = null;//from ww w.j av  a 2 s. c  om
        switch (type) {
        case 1:// hour
            interval = 1000 * 60 * 60 * i;
            t = new Timestamp(t1.getTime() + interval);
            break;
        case 2:// min
            interval = 1000 * 60 * i;
            t = new Timestamp(t1.getTime() + interval);
            break;
        case 3:// sec
            interval = 1000 * i;
            t = new Timestamp(t1.getTime() + interval);
            break;
        case 0: // defaut is day
            t = new Timestamp(t1.getTime() + interval);
            break;
        default:
            t = t1;
        }
        return t;
    }
}

Related

  1. convertTS2HHMM(Timestamp timeStamp)
  2. copyOrCreateTimestampNullsafe(Date date)
  3. createDateTimestamp(java.util.Date date)
  4. date2Timestamp(Date date)
  5. date2Timestamp(Date value)
  6. dateAndTimeToTimestamp(Date data, Time hora)
  7. dateIntToTimestamp(int dateInt)
  8. datesDiffer(Timestamp a, Timestamp b)
  9. dateStringToTimestamp(String dateStr)