Say for example I have two calendar object with the format of "MM/dd/yyyy". How do I subtract them and should return the number of days? For example, "9/7/2014" - "9/1/2014" and returns 7.
Calendar calendar = Calendar.getInstance();
Calendar today = Calendar.getInstance();
You may try like this:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH,7);
calendar.set(Calendar.MONTH,8);
calendar.set(Calendar.YEAR, 2014);
Calendar today = Calendar.getInstance();
long difference = today.getTimeInMillis() - calendar.getTimeInMillis();
int days = (int) (difference/ (1000*60*60*24));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With