查询当前日期是星期几

    public static String getWeek(String date) throws ParseException {
        String[] weeks = {"1","2","3","4","5","6","7"};
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
        cal.setTime(simpleDateFormat.parse(date));
        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if(week_index<0){
            week_index = 0;
        }
        return weeks[week_index];
    }


    public static void main(String[] args) throws ParseException {
        System.out.println(TimingHd.getWeek("2022-05-28"));
    }

 

posted @ 2022-05-28 10:47  _Lawrence  阅读(112)  评论(0编辑  收藏  举报