Answers for "how to add seconds to java date"

0

add second to date java

/*  w  w w  .  j  a va  2s .  c om*/
import java.util.Calendar;
import java.util.Date;

public class Main {

  public static void main(String[] args) {
    System.out.println(addSeconds(new Date(), 100));
  }

  public static Date addSeconds(Date date, Integer seconds) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.SECOND, seconds);
    return cal.getTime();
  }
}
Posted by: Guest on October-14-2020
0

add seconds to today date and time java

Calendar calendar = Calendar.getInstance(); // gets a calendar using the default time zone and locale.
calendar.add(Calendar.SECOND, 5);
System.out.println(calendar.getTime());
Posted by: Guest on June-24-2021

Code answers related to "how to add seconds to java date"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language