public static void main(String[] args) throws ParseException {
String[] weekDays = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
//获取当前时间(yyyy-MM-dd)格式
String date ="2023-04-24";
//转换为Date类型
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = sdf.parse(date);
//判断日期是星期几
Calendar cal = Calendar.getInstance();
cal.setTime(date1);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;
System.out.println(weekDays[w]);
}
JAVA中根据一个任意日期判断星期几
猜你喜欢
转载自blog.csdn.net/ssghzxc/article/details/130154757
今日推荐
周排行