编程语言
首页 > 编程语言> > java获取date是星期几

java获取date是星期几

作者:互联网

代码

 /**
     * 获取当前日期是星期几<br>
     * 
     * @param dt
     * @return 当前日期是星期几
     */
    public static String getWeekOfDate(Date dt) {
        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;
        return weekDays[w];
    }

标签:星期,java,String,weekDays,cal,date,return,dt,Calendar
来源: https://blog.csdn.net/qq_34626094/article/details/123225809