How can I get x
which should be 31 days before current_date
?
x(date)___________________________current_date
31
Just subtract 31 days. For example:
LocalDate current = new LocalDate(2015, 6, 19);
LocalDate x = current.minusDays(31); // 2015-05-19
To get the current date, you could use:
LocalDate current = new LocalDate(); // Default time zone
or
LocalDate current = new LocalDate(zone); // Some specific zone
Or you may want to create your own "clock" representation which is able to give you the current Instant
, in which case you'd use:
LocalDate current = clock.getCurrentInstant().toDateTime(zone).toLocalDate();
(That lets you use dependency injection to write simpler unit tests with a fake clock.)
See more on this question at Stackoverflow