add seconds to date java code example
Example 1: java Calendar add time
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -15);
calendar.add(Calendar.MONTH, 4);
Example 2: add second to date java
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();
}
}