import java.io.*;
import java.util.*;
import java.util.Date.*;
import java.util.Calendar;
import java.lang.Math.*;
import java.util.StringTokenizer;
public class DateDemo
{
String s,s1;
int i;
int d,d1,m,m1,y,y1;
public void add(String a,String b)
{
s=a;
s1=b;
StringTokenizer ss=new StringTokenizer(s,"/");
while(ss.hasMoreTokens())
{
d=Integer.parseInt(ss.nextToken());
m=Integer.parseInt(ss.nextToken());
y=Integer.parseInt(ss.nextToken());
}
StringTokenizer st=new StringTokenizer(s1,"/");
while(st.hasMoreTokens())
{
d1=Integer.parseInt(st.nextToken());
m1=Integer.parseInt(st.nextToken());
y1=Integer.parseInt(st.nextToken());
}
Calendar c1=Calendar.getInstance();
Calendar c2=Calendar.getInstance();
c1.set(y,m,d);
c2.set(y1,m1,d1);
long t1=c1.getTimeInMillis();
long t2=c2.getTimeInMillis();
long t3=Math.abs(t1-t2);
i=60*1000*60*24;
System.out.println(t3);
long diff= t3/i;
System.out.println("Difference btn"+ s+" and"+s1+" is"+diff+"days");
}
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
DateDemo dd=new DateDemo();
System.out.println("Enter the date as dd/mm/yyyy");
String d1=br.readLine();
System.out.println("Enter second date as dd/mm/yy");
String d2=br.readLine();
dd.add(d1,d2);
}
} Labels: Java
Responses
0 Respones to " "
Post a Comment