Calendar c = Calendar.getInstance()
c.setTime(date)
int week_num =c.get(Calendar.WEEK_OF_YEAR)
System.out.print("是第"+week_num+"周")
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK)
switch(dayOfWeek){
case 1:System.out.println("星期日!")break
case 2:System.out.println("星期一!")break
case 3:System.out.println("星期二!")break
case 4:System.out.println("星期三!")break
case 5:System.out.println("星期四!")break
case 6:System.out.println("星期五!")break
case 7:System.out.println("星期六!")break
}
1、使用Calendar类\x0d\x0a/**\x0d\x0a* 获取当前日期是星期几\x0d\x0a*\x0d\x0a* @param dt\x0d\x0a* @return 当前日期是星期几\x0d\x0a*/\x0d\x0apublic static String getWeekOfDate(Date dt) {\x0d\x0aString[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}\x0d\x0aCalendar cal = Calendar.getInstance()\x0d\x0acal.setTime(dt)\x0d\x0aint w = cal.get(Calendar.DAY_OF_WEEK) - 1\x0d\x0aif (w 回答于 2022-11-16
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)