Write a program to find out the difference (in number of days) between given two dates in dd/mm/yyyy format

Chikul
Posted by Chikul under Others category on | Views : 3114
import java.util.Calendar;

public class DateDifferent
{
public static void main(String[] args)
{
Calendar calendar1 = Calendar.getInstance();
Calendar calendar2 = Calendar.getInstance();

calendar1.set(21, 01, 2008);
calendar2.set(18, 02, 2008);

long milliseconds1 = calendar1.getTimeInMillis();
long milliseconds2 = calendar2.getTimeInMillis();
long diff = milliseconds2 - milliseconds1;
long diffDays = diff / (24 * 60 * 60 * 1000);

System.out.println("\nThe Date Different Example");
System.out.println("Time in days: " + diffDays + " days.");
}
}

Comments or Responses

Posted by: Santosh4u on: 12/23/2009 Level:Bronze | Status: [Member]
Very Nice COde.
Keep it up.

Login to post response