Answers for "java add seconds to date"

1

how to add minutes in date in java

// Adding 10 mins using Date constructor.
Calendar date = Calendar.getInstance();
System.out.println("Current Date and TIme : " + date.getTime());
long timeInSecs = date.getTimeInMillis();
Date afterAdding10Mins = new Date(timeInSecs + (10 * 60 * 1000));
System.out.println("After adding 10 mins : " + afterAdding10Mins);
Posted by: Guest on September-11-2021
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

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language