- 计算两个日期之间的天数 1989-10-15(自定义)出生 到目前生活了多少天?
/*
* Copyright (c) 2020, 2023, MingZi.cn All rights reserved.
*
*/
package org.abc;
import jdk.swing.interop.SwingInterOpUtils;
import java.util.Calendar;
import java.util.Date;
/**
* <p>Project: jse2303 - D1</p>
* <p>Powered by MingZi On 2023-07-07 17:50:53</p>
* <p>描述:<p>
*
* @author MingZi [MingZi@182.com]
* @version 1.0
* @since 17
*/
public class D1 {
public static void main(String[] args) {
/* Date d = new Date();
System.out.printf("%tF %<tF%n",d);*/
//时间戳 long 数字表 毫秒表
//System.out.printf("%tF %<tF%n",System.currentTimeMillis());
//计算;两个日期有多少天 1989-11-15 00:00:00
Calendar c = Calendar.getInstance();
c.set(1989,Calendar.OCTOBER,15,00,00,00);
long ss = c.getTimeInMillis();
long nn = System.currentTimeMillis();
long ok = nn - ss;
long day = 1000*60*60*24;
long days = ok/day;
//System.out.println(days);
System.out.printf("%tY年%<tm月%<td日到%tY年%<tm月%<td日,共生活%d天%n",ss,nn,days);
}
}
运行结果如下图所示:
注:计算机的算法是从0开始作为1来计算的