Java Date and Time

Sort by

recency

|

1485 Discussions

|

  • + 0 comments
    public static String findDay(int month, int day, int year) {
        String [] daysOfWeek = {"SATURDAY", "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY",  "THURSDAY", "FRIDAY"};
        if (month < 3) {
            month += 12;
            year -= 1;
        }
        // h = (q + (13(m + 1)/5) + K + (K / 4) + (J / 4) + 5J) mod 7
        int dayOfWeek = (day + (13 * (month + 1) / 5) + year % 100 
            + (year % 100 / 4) + (year / 100 / 4) + 5 * (year / 100)) % 7;
        return daysOfWeek[dayOfWeek];
    }
    
  • + 1 comment
     public static String findDay(int month, int day, int year) {
            return LocalDate.of(year, month, day).getDayOfWeek().toString();
        }
    
    • + 0 comments

      Why is this answer get downvoted? SMH

  • + 0 comments

    Calendar is no longer advised, why does the problem include it rather than the newer api?

  • + 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];
    }
    

    }

  • + 0 comments
    public static String findDay(int month, int day, int year) {
           Calendar cal = Calendar.getInstance();  
            cal.set(year, month - 1, day);  
            return cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.US).toUpperCase();  
        }