import java.util.GregorianCalendar;
public class FullYear {
public static void main(String[] args) {
GregorianCalendar cal1 = new GregorianCalendar(2011,2,9);
GregorianCalendar cal2 = new GregorianCalendar(2011,2,12);
long ms1 = cal1.getTime().getTime();
long ms2 = cal2.getTime().getTime();
long difMs = ms2-ms1;
long msPerDay = 1000*60*60*24;
System.out.println(difMs);
System.out.println(msPerDay);
double days = difMs / msPerDay;
System.out.println(days);
GregorianCalendar cal11 = new GregorianCalendar(2011,2,9);
GregorianCalendar cal22 = new GregorianCalendar(2011,2,19);
long ms11 = cal11.getTime().getTime();
long ms22 = cal22.getTime().getTime();
long difMs1 = ms22-ms11;
long msPerDay1 = 1000*60*60*24;
System.out.println(difMs1);
System.out.println(msPerDay1);
double days2 = difMs1 / msPerDay1;
System.out.println(days2);
}
}
这输出3.0和9.0(我期望10 !!)。这是整数除法,因此9.0实际上是9.95。但是,我的问题是......
第一个差异不应该是240小时吗?