0

我正在使用 Joda-Time 并试图找出日期之间的差异。

我的代码有问题吗?

这是我的代码:

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();

我正在使用 JOptionPane 来查看结果,它告诉我在 (age1) 上得到了 0。

4

1 回答 1

4

您需要在 LocalDate 定义中添加引号"以使用带有String参数的构造函数:

LocalDate startDate = new LocalDate("1999-07-18");
LocalDate endDate = new LocalDate("2013-07-18");

您所写的计算结果为longs,而构建的两个日期实际上相隔 0 年。

于 2013-03-20T09:46:32.393 回答