-
-
Save fuentesj/771e420af553025a12ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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