Java examples for java.time:Week
Returns the week number of the specified date.
//package com.java2s; import java.time.LocalDate; import java.time.temporal.WeekFields; public class Main { /**//from ww w .ja v a 2 s .c o m * Returns the week number of the specified date. * * @param date date * @param weekStartsSunday flag whether the week starts on sunday or monday * @return week number (1 to 53) */ public static int getWeekNumber(final LocalDate date, final boolean weekStartsSunday) { final WeekFields weekField = weekStartsSunday ? WeekFields.SUNDAY_START : WeekFields.ISO; return date.get(weekField.weekOfWeekBasedYear()); } }