Mike3355
Mike3355

Reputation: 12081

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

I have the following method and I am trying to compare a newly created OffsetDateTime to the below class:

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());

    }

However I am getting the following error:

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

---------------UPDATE ONE----------------

I tried the following but got the error below:

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;

    }

Upvotes: 2

Views: 580

Answers (1)

s7vr
s7vr

Reputation: 75934

You can also try something like this to get the OffsetDateTime from 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 
}

Upvotes: 2

Related Questions