I have a simple program that asks a user to enter a date in a MM-dd-yyyy format. How can I get the day of the year from this input? For example if the user enters "06-10-2008" the day of the year would be the 162nd day considering this was a leap year.
Here's my code so far:
System.out.println("Please enter a date to view (MM/DD/2008):");
String date = sc.next();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
Date date2=null;
try {
//Parsing the String
date2 = dateFormat.parse(date);
} catch (ParseException e) {
System.out.println("Invalid format, please enter the date in a MM-dd-yyyy format!");
continue;
} //End of catch
System.out.println(date2);
}