javalocaldatedaterfc2445

AccountingDate (ChronoLocalDate) to Instant in java


I'm using the AccountingDate implemented into this project.

public final class AccountingDate extends AbstractDate implements ChronoLocalDate, Serializable {}

Do you know a way to convert an AccountingDate to Instant or LocalDate?


Solution

  • AccountingDate implements ChronoLocalDate, which supports all date based ChronoFields, so it supports ChronoFields.EPOCH_DAY, so LocalDate.from works:

    LocalDate.from(accountingDate)
    

    To convert a date to an Instant, you need two more pieces of information:

    If we assume the time is midnight, and the zone offset being UTC, we can do:

    accountingDate.atTime(LocalTime.MIDNIGHT).atZone(ZoneOffset.UTC).toInstant()