Using Android and Java 8, how can I get unix timestamps back in time?
E.g.
- Exactly 3 years back from now
- Exactly 2 months back from now
- Exactly 1 day back from now
- etc
I know I can get current timestamp using System.currentTimeMillis() / 1000L (you could also use Instant.now().getEpochSecond() from the new java.time, but this requires Android API > 25). Now I need to get offset and substract it. I could use TimeUnit.Days.toSeconds(), but if I want to substract years, it does not have YEAR unit and I don't want to mess with leap years myself.
Is there a simple way to do this?