Java SQL Date Add addDate(java.util.Date date, int day)

Here you can find the source of addDate(java.util.Date date, int day)

Description

add Date

License

Open Source License

Declaration

public static java.util.Date addDate(java.util.Date date, int day) 

Method Source Code


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

import java.util.Calendar;

public class Main {

    public static java.util.Date addDate(java.util.Date date, int day) {
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTimeInMillis(getMillis(date) + ((long) day) * 24 * 3600 * 1000);
        return c.getTime();
    }/* ww w.  j av a2 s  .  c om*/

    public static java.util.Date addDate(java.util.Date date, long mm) {
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTimeInMillis(getMillis(date) + mm);
        return c.getTime();
    }

    public static long getMillis(java.util.Date date) {
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTime(date);
        return c.getTimeInMillis();
    }

    public static String getTime() {
        Timestamp time = new Timestamp(Calendar.getInstance().getTime().getTime());
        return time.toString();
    }
}

Related

  1. add(Date date, int unit, int amount)
  2. addDate(int add, java.util.Date d)
  3. addDate(String date)
  4. addDays(Date date, int days)
  5. addDaysToSQLDate(java.sql.Date date, int days)
  6. addMesData(Date dtReferencia, int mes)