Java Date add day

Description

Java Date add day

import java.util.Date;

public class Main {
  public static void main(String[] argv) {
    Date d = new Date();
    long day = 42;
    System.out.println(addDate(d, day));
  }// w  w  w .  java  2 s.  co  m

  public static Date addDate(Date d, long day) {
    long time = d.getTime();
    day = day * 24 * 60 * 60 * 1000;
    time += day;
    return new Date(time);
  }
}



PreviousNext

Related