wulev

Days Between 2 Dates

May 20th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Date;
  3. import org.joda.time.DateTime;
  4. import org.joda.time.Days;
  5.  
  6.  
  7. public class _07_DaysBetweenTwoDates {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner input = new Scanner(System.in);
  12.         String startDate = input.nextLine();
  13.         String endDate = input.nextLine();
  14.         String[] firstDate = startDate.split("-");
  15.         String[] secondDate = endDate.split("-");
  16.         DateTime first = new DateTime(Integer.parseInt(firstDate[2]),  
  17.                 Integer.parseInt(firstDate[1]), Integer.parseInt(firstDate[0]), 0,0);
  18.         DateTime second = new DateTime(Integer.parseInt(secondDate[2]),
  19.                 Integer.parseInt(secondDate[1]), Integer.parseInt(secondDate[0]), 0,0);
  20.         int days = Days.daysBetween(first, second).getDays();
  21.         System.out.println(days);
  22.        
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment