Java Date and Time

  • + 0 comments

    I couldn't figure out how to solve the problem using the Calender class.

    So I used LocalDateTime and DateTimeFormatter classes instead. This approach appears clearer to me also. Note :- You would also need to import java.time.LocalDateTime and java.time.format.DateTimeFormatter on the toplevel of the file. This is the code of the method -

    public static String findDay(int month, int day, int year) {
            LocalDateTime date = LocalDateTime.of(year, month, day,0,0);
            
            DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("EEEE");
            
            String formattedDate = date.format(dateFormat).toString();
            
            String DAY = formattedDate.toUpperCase();
            return DAY;
        }