Kotlinx date time how to get last year?

252 Views Asked by At

I'm using Kotlinx.dateTime. And I need to get the current date and the current date - 12 months.

Here is my code for current date:

val currentDate: LocalDateTime = Clock.System.now()
        .toLocalDateTime(TimeZone.currentSystemDefault())

But I can't understand how to retrieve current date - 12 months. Because as far as I can see kotlin.time.Duration does not contain Duration.Months, only NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS. So I can't write something like this:

val lastYear: LocalDateTime = Clock.System.now().minus(12.months).toLocalDateTime(
        TimeZone.currentSystemDefault()

Please help me.

0

There are 0 best solutions below