/*
* 计算两个日期之间相差的周数 天数
*/
public static void getBetweenDate(){
String strDateStar = "2021-9-2";
String strDateEnd = "2022-5-8";
try{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dateStart = sdf.parse(strDateStar );
Date dateEnd = sdf.parse(strDateEnd );
int betweenDay = (int) ((dateEnd.getTime() - dateStart.getTime()) / (1000*60*60*24) );
int betweenWeek = (int) ((dateEnd.getTime() - dateStart.getTime()) / (1000*60*60*24)/7 );
System.out.println("【" + strDateStar + "】和【" + strDateEnd + "】相差" + betweenDay + "天");
System.out.println("【" + strDateStar + "】和【" + strDateEnd + "】相差" + betweenWeek + "周");
}
catch(Exception ex){
ex.printStackTrace();
}
}
【计算两个日期之间相差的周数 天数】
于 2022-06-21 09:50:01 首次发布