Friday, January 27, 2023

t+2 days in Java

import java.time.LocalDate;
import java.time.DayOfWeek;

public class DateFetcher {

    public static void main(String[] args) {

        LocalDate currentDate = LocalDate.now();

        LocalDate tPlusTwoDate = currentDate;
        int counter = 0;

        while (counter < 2) {
            tPlusTwoDate = tPlusTwoDate.plusDays(1);
            if (tPlusTwoDate.getDayOfWeek() != DayOfWeek.SATURDAY && tPlusTwoDate.getDayOfWeek() != DayOfWeek.SUNDAY) {
                counter++;
            }
        }

        System.out.println("T+2 date (excluding weekends): " + tPlusTwoDate);
    }
}

No comments:

Post a Comment