This question already has an answer here:
can anyone tell how to subtract string "after" from "today" to get days difference.
import java.text.*;
import java.util.*;
public class Main {
public static void main(String args[]){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");
Calendar cal=Calendar.getInstance();
String today=sdf.format(cal.getTime());
System.out.println(today);
cal.add(Calendar.DATE, 20);
String After=sdf.format(cal.getTime());
System.out.println(After);
}
}
It would be easier with java8 where you dont need to subtract long values represent of date and change back to days, hours and minutes.
Period
&LocalDate
class are available in #java8LocalDate
docsIf you are not using java8, use joda-time library's
org.joda.time.Days
utility to calculate thistry this...
May it helps you.
Using JodaTime, in case you don't have Java 8
Which outputs...
This may help You..