I have the following code that I want to migrate to Java 17:
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
?
edit: I tried this
from: log.setTimestamp(dateFormatter.print(auditLog.getInsertedDate().withZone(DateTimeZone.UTC)));
to: log.setTimestamp(dateFormatter.print(auditLog.getInsertedDate().atZoneSameInstant(ZoneOffset.UTC)));
I get for this line: auditLog.getInsertedDate().atZoneSameInstant(ZoneOffset.UTC)
error:
Cannot resolve method 'print(ZonedDateTime)'
Can you advice how to solve this?