Diff No of Days Betwwen Two Days

package com.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.joda.time.Days;

public class Demo {
public static void main(String[] args) throws ParseException {

Calendar cal1 = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();

SimpleDateFormat sdf = new SimpleDateFormat(“dd-MM-yyyy”);

Date date = sdf.parse(“29-02-2016”);
cal1.setTime(date);
date = sdf.parse(“01-03-2016”);
cal2.setTime(date);

//cal1.set(2008, 8, 1);
//cal2.set(2008, 9, 31);
System.out.println(“Days= “+daysBetween(cal1.getTime(),cal2.getTime()));

}

publicĀ  static int daysBetween(Date d1, Date d2){
return (int)( (d2.getTime() – d1.getTime()) / (1000 * 60 * 60 * 24));
}

}

Leave a Reply

Your email address will not be published. Required fields are marked *

31 − = 27