Java examples for java.time:Day
days Between Date And Last Friday
import java.time.DayOfWeek; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Date; public class Main{ public static int daysBetweenDateAndLastFriday(LocalDateTime date) { int dateDayOfWeek = date.getDayOfWeek().getValue(); int fridayDayOfWeek = DayOfWeek.FRIDAY.getValue(); if (dateDayOfWeek > fridayDayOfWeek) { return dateDayOfWeek - fridayDayOfWeek; } else {//w w w . jav a 2 s .c o m return 7 - (fridayDayOfWeek - dateDayOfWeek); } } }