Java 计算两个日期相差天数
程序员文章站
2022-03-06 11:58:20
...
import java.util.Calendar;
public class CalendarTest2 {
public static void main(String[] args) {
//计算两个日期相差天数
Calendar c1=Calendar.getInstance();
c1.set(2018, 12-1,12);
Calendar c2=Calendar.getInstance();
c2.set(2018, 12-1,17);
long t1=c1.getTimeInMillis();
long t2=c2.getTimeInMillis();
long days=(t2-t1)/(24*60*60*1000);
System.out.println(days);
}
}