Java Date and Time

Sort by

recency

|

1461 Discussions

|

  • + 0 comments

    import java.time.LocalDate; import java.util.*;

    public class DateAndTime { public static String findDay(int month,int day,int year){

       return LocalDate.of(year, month, day).getDayOfWeek().toString();
    
    }
    public static void main(String[] args) {
     Scanner sc=new Scanner(System.in);
    
     int month=sc.nextInt();
     int day=sc.nextInt();
     int year=sc.nextInt();
    
    
     System.out.println(findDay(month, day, year));
    
    
    
    
    
    
    
    
    }
    

    }

  • + 0 comments
        public static String findDay(int month, int day, int year) {
                LocalDate date = LocalDate.of(year, month, day);
                return date.getDayOfWeek().toString();
        }
    
  • + 0 comments
    public static String findDay(int month, int day, int year) {
    
        LocalDate date = LocalDate.of(year, month, day);
    
        DayOfWeek dayOfWeek = date.getDayOfWeek();
        String dayOfWeekName = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.ENGLISH);
    
        return dayOfWeekName.toUpperCase();
    
    }
    
  • + 1 comment

    Easy Solution

    class Result {

    /*
     * Complete the 'findDay' function below.
     *
     * The function is expected to return a STRING.
     * The function accepts following parameters:
     *  1. INTEGER month
     *  2. INTEGER day
     *  3. INTEGER year
     */
    
    public static String findDay(int month, int day, int year) {
    
        Calendar calendar = Calendar.getInstance();
    
        calendar.set(year,month-1,day);
    
        System.out.println(calendar.getTime());
    
        int res = calendar.get(calendar.DAY_OF_WEEK);
    
        switch (res) {
            case 1 -> {return "SUNDAY";}
            case 2 -> {return "MONDAY";}
            case 3 -> {return "TUESDAY";}
            case 4 -> {return "WEDNESDAY";}
            case 5 -> {return "THURSDAY";}
            case 6 -> {return "FRIDAY";}
            case 7 -> {return "SATURDAY";}
            default -> {return "nachobc";}
        }
    
    }
    

    }

  • + 0 comments

    my answer by pass All testcase

    public static String findDay(int month, int day, int year) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month - 1, day); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); System.out.println(dayOfWeek); String[] dayOf = { "SUNDAY", "MONDAY",
    "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" }; return dayOf[dayOfWeek - 1]; } }