how to set first day of the year for this(my) program correctly ?
firstly tried and failed with:
LocalDate now = LocalDate.now();
LocalDate firstDay = now.with(firstDayOfYear());
changed all to "set" still wrong output.
thank you
package com.codegym.task.task08.task0827;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import static java.time.temporal.TemporalAdjusters.firstDayOfYear;
import static java.time.temporal.TemporalAdjusters.lastDayOfYear;
/*
Working with dates
*/
public class Solution {
public static void main(String[] args) {
System.out.println(isDateOdd("JANUARY 1 2000"));
}
public static boolean isDateOdd(String date) {
SimpleDateFormat format = new SimpleDateFormat("MMMM d yyyy");
Date yearStartTime = new Date();
yearStartTime.setHours(0);
yearStartTime.setMinutes(0);
yearStartTime.setSeconds(0);
yearStartTime.setDate(1); // first day of the month
yearStartTime.setMonth(0); // JANUARY
Date currentTime = new Date();
long msTimeDifference = currentTime.getTime() - yearStartTime.getTime();
long msDay = 1000 * 60 * 60 * 24; // millisec in 24
int dayCount = (int)(msTimeDifference / msDay);
if(dayCount % 2 != 0)
return true;
else return false;
}
}