AlexKondov

Java Days Between Two Dates

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