Answers for "add seconds to date java"

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
1

java Calendar add time

Calendar calendar = Calendar.getInstance();  
// 15 days ago
calendar.add(Calendar.DATE, -15); 
// After 4 months
calendar.add(Calendar.MONTH, 4);
Posted by: Guest on August-28-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language