[Java] 计算两个日期相差天数 →→→→→进入此内容的聊天室

来自 , 2020-05-15, 写在 Java, 查看 167 次.
URL http://www.code666.cn/view/f770b62b
  1. import java.util.*;
  2.  
  3. public class Test {
  4.         public static void main(String args[]) {
  5.                 Calendar calendar = Calendar.getInstance();
  6.                 calendar.setTime(new Date());
  7.  
  8.                 calendar.set(1991, 7, 7);
  9.                 long time_1 = calendar.getTimeInMillis();
  10.  
  11.                 calendar.set(2012, 8, 31);
  12.                 long time_2 = calendar.getTimeInMillis();
  13.  
  14.                 long space = (time_2 - time_1) / (1000 * 60 * 60 * 24);
  15.                 System.out.println("至今我活了大约 " + space + " 天");
  16.         }
  17. }
  18.  

回复 "计算两个日期相差天数"

这儿你可以回复上面这条便签

captcha