//获取当天
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1; // 注意:月份是从0开始的
int day = calendar.get(Calendar.DAY_OF_MONTH);
//基姆拉尔森计算公式根据日期判断星期几
public String CalculateWeekDay(int y, int m, int d) {
if(m < 1 || m >12){
System.out.println("你输入的月份不再范围内,请重新输入!");
}
if (m == 1 || m == 2) {
m += 12;
y--;
}
String week = null;
int iWeek = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
switch (iWeek) {
case 0:
week = "星期一";
break;
case 1:
week = "星期二";
break;
case 2:
week = "星期三";
break;
case 3:
week = "星期四";
break;
case 4:
week = "星期五";
break;
case 5:
week = "星期六";
break;
case 6:
week = "星期日";
break;
default:
break;
}
return week;
}
// 获取未来一星期内的日期集合
public static List<String> getNextSevenDays() {
List<String> nextSevenDays = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM.dd");
for (int i = 0; i < 6; i++) {
nextSevenDays.add(dateFormat.format(calendar.getTime()));
calendar.add(Calendar.DATE, 1); // 增加一天
}
return nextSevenDays;
}