Skip to content

Instantly share code, notes, and snippets.

@fuentesj
Created February 10, 2015 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuentesj/771e420af553025a12ba to your computer and use it in GitHub Desktop.
Save fuentesj/771e420af553025a12ba to your computer and use it in GitHub Desktop.
package challenge201;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Scanner;
/**
* Created by jon on 2/9/15.
*/
public class Solution {
public static void main(String[] args) {
System.out.print("Please enter a date with the format yyyy-MM-dd: ");
Scanner scanner = new Scanner(System.in);
String dateString = scanner.nextLine();
String[] dateArray = dateString.split("-");
LocalDate targetDate = LocalDate.of(Integer.parseInt(dateArray[0]), Integer.parseInt(dateArray[1]), Integer.parseInt(dateArray[2]));
LocalDate today = LocalDate.now();
Long numberOfDaysBetween = ChronoUnit.DAYS.between(today, targetDate);
System.out.println(numberOfDaysBetween + " days from " + today.toString() + " to " + targetDate.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment