How to determine day of week by passing specific date?

前端 未结 25 2127
夕颜
夕颜 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:34

    private String getDay(Date date){
    
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE");
        //System.out.println("DAY "+simpleDateFormat.format(date).toUpperCase());                       
        return simpleDateFormat.format(date).toUpperCase();
    }
    
    private String getDay(String dateStr){
        //dateStr must be in DD-MM-YYYY Formate
        Date date = null;
        String day=null;
    
        try {
            date = new SimpleDateFormat("DD-MM-YYYY").parse(dateStr);
    
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE");
            //System.out.println("DAY "+simpleDateFormat.format(date).toUpperCase());
            day = simpleDateFormat.format(date).toUpperCase();
    
    
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    
        return day;
    }
    

提交回复
热议问题