I need help with a little excercise. I am to write a method which returns true or false when a dayOfYear is odd or not respectively. I have to work with a String date ("MAY 22 2013"). I have no other instructions than to print true or false.
So my first thought and intention was to parse the String into a LocalDate date and then use the getDayOfYear() method. This is my code so far:
public static void main (String[]args){
System.out.println(isOddDate("MAY 22 2013"));
}
public static boolean isOddDate (String date) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd yyyy");
LocalDate localDate = LocalDate.parse(date, formatter);
if (localDate.getDayOfYear()%2 != 0) {
return true;
} else {
return false;
}
}
I get the error message Text 'MAY 22 2013' could not be parsed at index 0. I tried the java docs, several other tutorials and I have no idea what exactly I am doing wrong. Can somebody give me a hint please?