I am trying to calculate the no. of days elapsed in a year with the year matching the inputted date example:
If the user enters 13/01/2008 it will say 12 days have passed since the beginning of the year
This is my school assignment, Thanks.
so far I have Taken in the input of date and I want to use that to calculate the no. days elapsed in that year.
public static void main(String[] args)
{
final Locale defaultFormattingLocale
= Locale.getDefault(Locale.Category.FORMAT);
final String defaultDateFormat = DateTimeFormatterBuilder
.getLocalizedDateTimePattern(FormatStyle.SHORT, null,
IsoChronology.INSTANCE, defaultFormattingLocale);
final DateTimeFormatter dateFormatter
= DateTimeFormatter.ofPattern(defaultDateFormat, defaultFormattingLocale);
Scanner inputScanner = new Scanner(System.in);
System.out.println("Enter a date in the DD/MM/YYYY Format");
String dateString = inputScanner.nextLine();
try
{
LocalDate inputDate = LocalDate.parse(dateString, dateFormatter);
System.out.println("Date entered was " + inputDate);
} catch (DateTimeParseException dtpe)
{
System.out.println("Invalid date - Enter a date in the format DD/MM/YYYY");
}
}
}