How to determine day of week by passing specific date?

前端 未结 25 1856
夕颜
夕颜 2020-11-22 05:12

For Example I have the date: \"23/2/2010\" (23th Feb 2010). I want to pass it to a function which would return the day of week. How can I do this?

I

25条回答
  •  耶瑟儿~
    2020-11-22 05:54

    //to get day of any date
    
    import java.util.Scanner; 
    import java.util.Calendar; 
    import java.util.Date;
    
    public class Show {
    
        public static String getDay(String day,String month, String year){
    
    
                String input_date = month+"/"+day+"/"+year;
    
                Date now = new Date(input_date);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(now);
                int final_day = (calendar.get(Calendar.DAY_OF_WEEK));
    
                String finalDay[]={"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"};
    
                System.out.println(finalDay[final_day-1]);
    
        }
    
        public static void main(String[] args) { 
                Scanner in = new Scanner(System.in); 
                String month = in.next(); 
            String day = in.next();
                String year = in.next();
    
                getDay(day, month, year);
        }
    
    }
    

提交回复
热议问题