Java Two Dates Difference In Days

How To Get Days Difference Between 2 Dates Using Java NetBeans

Days Difference Between Two Dates In Java



In this Java Tutorial we will see How To Get The Number Of Days Diffrence Between Two Date Using Calendar On Button Click Event In Java NetBeans .




Project Source Code:

            
private void jButtonDaysDiffActionPerformed(java.awt.event.ActionEvent evt) {                                                
        
        Calendar c1 = new GregorianCalendar(2000,Calendar.JULY,25);
        Calendar c2 = new GregorianCalendar(2007,Calendar.DECEMBER,31);
        
        // 1000 x 60 X 60 X 24 = MS per Day
        
        System.out.println("Days Diff = " + (c2.getTimeInMillis() - c1.getTimeInMillis()) / (1000*60*60*24));
        
    }


OutPut: 
Days Diff = 2715




Share this

Related Posts

Previous
Next Post »