使用java获取到目前为止你活了多少天

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 + “天”;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值