days Between Date And Last Friday - Java java.time

Java examples for java.time:Day

Description

days Between Date And Last Friday

Demo Code


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);
        }
    }
}

Related Tutorials