Невозможно получить OffsetDateTime из TemporalAccessor: 2016-12-15T15:58:03Z типа java.time.Instant

У меня есть следующий метод, и я пытаюсь сравнить недавно созданный OffsetDateTime с классом ниже:

public OffsetDateTime getCreatedDateFromToken(String token) {
        logger.debug("Entered getCreatedDateFromToken  "+token);
        OffsetDateTime o = (OffsetDateTime.from(getClaimsFromToken(token).getIssuedAt().toInstant()));
        logger.debug("OffSetTimeDate is "+o);

        return OffsetDateTime.from(getClaimsFromToken(token).getIssuedAt().toInstant());

    }

Однако я получаю следующую ошибку:

java.time.DateTimeException: Unable to obtain OffsetDateTime from TemporalAccessor: 2016-12-15T15:58:03Z of type java.time.Instant

--------------- ОБНОВЛЕНИЕ ОДИН ----------------

Я попробовал следующее, но получил ошибку ниже:

ava.time.DateTimeException: Unable to obtain OffsetDateTime from TemporalAccessor: 2016-12-15T19:51:57Z of type java.time.Instant

@Override
    public OffsetDateTime getCreatedDateFromToken(String token) {
        logger.debug("Entered getCreatedDateFromToken  "+token);
        //OffsetDateTime o = (OffsetDateTime.from(getClaimsFromToken(token).getIssuedAt().toInstant()));
        OffsetDateTime oo = OffsetDateTime.ofInstant(Instant.from(OffsetDateTime.from(getClaimsFromToken(token).getIssuedAt().toInstant())), ZoneOffset.UTC);
        //logger.debug("OffSetTimeDate is "+o);

        return oo;

    }

1 ответ

Решение

Вы также можете попробовать что-то подобное, чтобы получить OffsetDateTime из Instant.

public OffsetDateTime getCreatedDateFromToken(String token) {
    logger.debug("Entered getCreatedDateFromToken  "+token);
    OffsetDateTime offsetDateTime = getClaimsFromToken(token).getIssuedAt().toInstant().atOffset(ZoneOffset.UTC);
    logger.debug("OffSetTimeDate is "+o);
    return offsetDateTime 
}
Другие вопросы по тегам