Skip to content

Cannot resolve method 'withZone' in 'OffsetDateTime' #122

@rcbandit111

Description

@rcbandit111

I have the following code that I want to migrate:

Gradle dependency:

implementation 'org.jadira.usertype:usertype.core:7.0.0.CR1'

Entity:

    import org.joda.time.DateTime;

    @Entity
    @Table(name = "logs")
    public class Log {
    
      @Column(name = "inserted_date")
      @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
      private DateTime insertedDate;
    }


.....

DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yy-mm-dd'T'HH:mm:ss'Z'");

log.setInsertedDate(DateTime.now());
dateFormatter.print(log.getInsertedDate().withZone(DateTimeZone.UTC)));

I updated the code to this:

Entity:

    import java.time.OffsetDateTime;

    @Entity
    @Table(name = "logs")
    public class Log {
    
      @Column(name = "inserted_date")
      private OffsetDateTime insertedDate;
    }


.....

DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yy-mm-dd'T'HH:mm:ss'Z'");

log.setInsertedDate(OffsetDateTime.now());
dateFormatter.print(log.getInsertedDate().withZone(DateTimeZone.UTC)));

But I get error Cannot resolve method 'withZone' in 'OffsetDateTime'. Do you know what is the proper way to update method withZone?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions