THE ZEPINT NETWORK

programmer assist

Java Java XML Feeds

Java Questions Java Solutions Java Articles

Java is an object-oriented programming language developed initially by James Gosling and colleagues at Sun Microsystems. The language, initially called Oak (named after the oak trees outside Gosling's office), was intended to replace C++, although the feature set better resembles that of Objective C. Java should not be confused with JavaScript, which shares only the name and a similar C-like syntax. Sun Microsystems currently maintains and updates Java regularly.

Calculate number of days between two dates

DiggBlinkRedditDeliciousTechnorati

question by Bejaan | Easy

Hi everybody!

I want to calculate how many days between two given days (java.sql.Date) and check for leap year(get the right number of days in the february month).

I don't find any routines...can you help me?

Thanks!

Post reply Subscriptions

Re: Calculate number of days between two dates

reply by Srirangan

Date d1, d2; // Based on "Date{}".
int dayDifference = (d1.getTime()/24*3600*1000 ? d2.getTime()/24*3600*1000);

Calendar c1 = Calendar.getInstance(); // Based on "Calendar{}".
c1.setTime(d1);
Calendar c2 = Calendar.getInstance();
c2.setTime(d2);
int dayDifference =
c1.getTimeInMillis()/24*3600*1000 ? c2.getTimeInMillis()/24*3600*1000;

;JOOP!

Post reply Subscriptions

Got a Java Question?

Just Sign Up and ask the top Java experts!

Search via Google

User Login

Email Address

Password

Java Experts

Rank Expert Points
#1 Srirangan 100
This a list of the Top Java experts, how many points do you have?

Leading Experts

Rank Expert Points
#1 frankzzsword 4600
#2 Bejaan 2900
#3 csfreak 1100
#4 Anurag 700
#5 keyvez 700
#6 nnarasimha 600
#7 Nakata 600
#8 martinig 600
#9 mastercomputers 400
#10 Huntress 150
#11 Adkron 150
#12 Yogesh 100
#13 lexxwern 100
#14 Mustan Khan 100
#15 poizn 100
This is a list of overall best performing experts, how many points do you have?