public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
System.out.println(“请输入你的生日(格式:年-月-日):”);
String birthday = scanner.nextLine();
System.out.println(getDatePoor(birthday));
}
private static String getDatePoor(String birthday) throws Exception {
SimpleDateFormat formatter = new SimpleDateFormat(“yyyy-MM-dd”);
Date date = formatter.parse(birthday);
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = System.currentTimeMillis() - date.getTime();
// 计算差多少天
long day = diff / nd;
// 计算差多少秒//输出结果
// long sec = diff % nd % nh % nm / ns;
return day + “天”;
}
使用java获取到目前为止你活了多少天
最新推荐文章于 2024-08-29 20:24:08 发布