1

How do I build an Instant object whose value is one year ago today?

For example if right now is 2015-12-20T11:53 I want an Instant object containing 2014-12-20T11:53.

Instant has a minus function that receives a Duration but Duration doesn't have a years function. There is a class called Period that has a Period.years function but running Period.years(1).toStandardDuration() throws the following exception:

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

Benjy Kessler
  • 7,356
  • 6
  • 41
  • 69
  • Possible duplicate of [How to get previous month and years in java?](http://stackoverflow.com/questions/12814504/how-to-get-previous-month-and-years-in-java) – Przemek Dec 20 '15 at 12:05

1 Answers1

2

You should use the DateTime.minusYears(int years); method.

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

Benjy Kessler
  • 7,356
  • 6
  • 41
  • 69
Stultuske
  • 9,296
  • 1
  • 25
  • 37