How to determine day of week by passing specific date?

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

    public class TryDateFormats {
        public static void main(String[] args) throws ParseException {
            String month = "08";
            String day = "05";
            String year = "2015";
            String inputDateStr = String.format("%s/%s/%s", day, month, year);
            Date inputDate = new SimpleDateFormat("dd/MM/yyyy").parse(inputDateStr);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(inputDate);
            String dayOfWeek = calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.US).toUpperCase();
            System.out.println(dayOfWeek);
        }
    }
    

提交回复
热议问题