Tuesday, September 22, 2009

DateDiffDays and max date detween two date's

1.Date Diff Days :
static public long dateDiffDays(Date d1, Date d2)
{
Calendar c = Calendar.getInstance();
c.clear();
c.setTime(d1);
long t1 = c.getTimeInMillis();

c.clear();
c.setTime(d2);
long t2 = c.getTimeInMillis();

return (t1 - t2) / 1000L / 60L / 60L / 24L;
}
2. Max date :
static public Date max(Date d1, Date d2) {
if (d1==null) return d2;
if (d2==null) return d1;
if (d1.after(d2)) return d1;
return d2;
}

No comments: