计算一年前的今天

Calculating one year ago today

如何构建一个 Instant 对象,其值为一年前的今天?

例如,如果现在是 2015-12-20T11:53 我想要一个包含 2014-12-20T11:53.

Instant 对象

Instant 有一个 minus 函数接收 DurationDuration 没有 years 函数。有一个名为 Period 的 class 具有 Period.years 函数,但 运行 Period.years(1).toStandardDuration() 抛出以下异常:

java.lang.UnsupportedOperationException: Cannot convert to Duration as this period contains years and years vary in length

您应该使用 DateTime.minusYears(int years); 方法。

http://www.joda.org/joda-time/apidocs/index.html