1.计算当天是开学第几周星期几
public static int getweek(Date d1, Date d2) {
// 获得当前日期与本周日相差的天数
Calendar cd = Calendar.getInstance();
cd.setTime(d2);
// 获得今天是一周的第几天,星期日是第一天,星期二是第二天......
int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK)-1 ; // 因为按中国礼拜一作为第一天所以这里减1
long daysBetween = (d1.getTime() - d2.getTime() + 1000000) / (60 * 60 * 24 * 1000);
int weekindex= (int) (daysBetween / 7+1);
if(dayOfWeek+daysBetween % 7>7){
weekindex+=1;
}
return weekindex;
}
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");
Date d=new Date();
String startday="2022-02-16";//开学日期
System.out.println("当天日期:"+format.format(d));
System.out.println("开学日期:"+startday);
//计算当前日期是开学的第几周
Date d1 = null;
try {
d1