Epi-week method for JAVA

334 views Asked by At

i need to get the epi-week of a given date,so it'd be very helpful if there is a method or api to achieve this for Java.

The definition for epi-week is the following "The first epi week of the year ends, by definition, on the first Saturday of January, as long as it falls at least four days into the month. Each epi week begins on a Sunday and ends on a Saturday."

thanks,

1

There are 1 answers

5
Meno Hochschild On

You can translate it to:

  • start of week = Sunday

  • minimalDaysInFirstWeek = 4

For Java pre 8, the class java.util.GregorianCalendar defines methods like setMinimalDaysInFirstWeek(4) and setFirstDayOfWeek(Calendar.SUNDAY)

For Java-8, you can refer to the class WeekFields

Update due to question in comment:

GregorianCalendar gcal = new GregorianCalendar(2013, Calendar.DECEMBER, 29);
gcal.setMinimalDaysInFirstWeek(4);
gcal.setFirstDayOfWeek(Calendar.SUNDAY);
int epiWeek = gcal.get(Calendar.WEEK_OF_YEAR);
System.out.println("epi-week=" + epiWeek); // epi-week=1