I feel that the approach I've gone for is a little round-about, I've also seen simpler solutions in other questions; can anyone help me see where I've gone wrong with my code please.
Thanks
package com.codegym.task.task08.task0827;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
/*
Working with dates
*/
public class Solution {
public static void main(String[] args) throws ParseException {
System.out.println(isDateOdd("MAY 1 2013"));
}
public static boolean isDateOdd(String date) throws ParseException {
DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
Date dateSimple = format.parse(date);
Calendar dateCal = Calendar.getInstance();
dateCal.setTime(dateSimple);
Calendar beginingOfYear = new GregorianCalendar(dateCal.get(Calendar.YEAR), 0, 1);
Date beginingOfYearDate = beginingOfYear.getTime();
long difference = dateSimple.getTime() - beginingOfYearDate.getTime();
long days = difference/(1000*3600*24);
int daysInt = (int) days;
if(daysInt%2 !=0){
return true;}
else {
return false;
}
}
}