Java Date and Time

  • + 0 comments

    public static String findDay(int month, int day, int year) { if (month <= 2) { month += 12; year--; }

        // Zeller's Congruence formula for the day of the week
        int K = year % 100; // Year of the century
        int J = year / 100; // Century
    
        int h = (day + (13 * (month + 1)) / 5 + K + K / 4 + J / 4 + 5 * J) % 7;
    
        // Array to map the result to the corresponding day of the week
        String[] days = {"SATURDAY", "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"};
        return days[h];
    }
    

    }