Answers for "add minutes to date java"

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

java calendar add minutes

String myTime = "14:10";
 SimpleDateFormat df = new SimpleDateFormat("HH:mm");
 Date d = df.parse(myTime); 
 Calendar cal = Calendar.getInstance();
 cal.setTime(d);
 cal.add(Calendar.MINUTE, 10);
 String newTime = df.format(cal.getTime());
Posted by: Guest on April-15-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language