[英]Finding difference between two dates using Joda in Java
I'm using Joda-Time and trying to find the difference between dates. 我正在使用Joda-Time并试图找出日期之间的差异。
Is there something wrong with my code? 我的代码有问题吗?
Here's my code : 这是我的代码:
LocalDate startDate = new LocalDate (19990-7-18);
LocalDate endDate = new LocalDate (2013-07-18);
Years Age = Years.yearsBetween(startDate, endDate);
int Age1 = Age.getYears();
String Age2 = new Integer(Age1).toString();
I'm using JOptionPane to view the result, and its telling I got 0 on (age1). 我正在使用JOptionPane查看结果,它告诉我在(age1)上得到0。
You need to add quotation marks "
to your LocalDate definitions to use the constructor that takes a String
parameter: 您需要在LocalDate定义中添加引号"
,以使用带有String
参数的构造函数:
LocalDate startDate = new LocalDate("1999-07-18");
LocalDate endDate = new LocalDate("2013-07-18");
What you have written evaluates to long
s, and the two dates constructed will in fact be 0 years apart. 您所写的内容将得出long
s,并且构造的两个日期实际上将相距0年。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.