> 游戏
java通过日期算星期几(java计算日期多少天后)
导语:干货!java由日期得到当天是星期几
public class DateToWeek {
public static String getDateToWeek() throws ParseException{
Calendar calendar=Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
String string=sdf.format(new Date());
Date date=sdf.parse(string);
calendar.setTime(date);
System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
String week="";
switch(calendar.get(Calendar.DAY_OF_WEEK)){
case 1:week="星期日";break;
case 2:week="星期一";break;
case 3:week="星期二";break;
case 4:week="星期三";break;
case 5:week="星期四";break;
case 6:week="星期五";break;
case 7:week="星期六";break;
}
return week;
}
}
本文内容由小开整理编辑!