gpt4 book ai didi

java - Java 中日期的年差

转载 作者:行者123 更新时间:2023-11-29 09:43:31 27 4
gpt4 key购买 nike

<分区>

Date currentDate=new Date();
DateFormat formatter=new SimpleDateFormat("dd-MM-yyyy");;
Date date =(Date)formatter.parse(birthDate); //birthDate is a String, in format dd-MM-yyyy
long diff = currentDate.getTime() - date.getTime();
long d=(1000*60*60*24*365);
long years = Math.round(diff / d);
age=(int) years;

年龄的值(value)是不正确的。我做错了什么?

Enter your birthdate: (in format dd-MM-yyyy)
25-07-1992
Current Date: Tue Apr 21 14:05:19 IST 2015
Birthday: Sat Jul 25 00:00:00 IST 1992

Output: Age is: 487

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com