How to get Balance days from 2 date?
How to get Balance days from 2 date? I have a simple calendar like below:
Calendar cal1 = Calendar.getInstance();
int year = 2007;
int month = 8;
int day = 1;
cal1.set(year,month,day);
Calendar now = Calendar.getInstance();
int nd = now.get(Calendar.DAY_OF_MONTH);
int nM = now.get(Calendar.MONTH)+1;
int ny = now.get(Calendar.YEAR);
now.set(ny,nM,nd);
if (now.before(cal1)){ . . . . . . . .
Anyone can tell me How to get the balance day(s) between now and cal1? Thank You.
# 2
Try this
import java.util.Calendar;
import java.util.GregorianCalendar;
public class DateDiff
{
public static void main(String[] args)
{
/*
* Note that months are zero-based and "8" is September. Using Calendar.AUGUST
* eliminates any source of confusion.
*/
Calendar futureDate = new GregorianCalendar(2007, Calendar.AUGUST, 1, 0, 0, 0);
Calendar now = Calendar.getInstance();
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
int count = 0;
while(now.before(futureDate))
{
now.add(Calendar.DATE, 1);
count++;
}
System.out.println("count = " + count);
}
}