나는 직선적 인 해결책이 없다고 생각합니다. 한 가지 해결 방법은 Timestamp
과 DateTime
필드를 POJO에두고 다음 예제와 같이 Timestamp
속성의 setter 메소드에서 DateTime
값을 설정하는 것입니다.
public class Pojo{
private Timestamp timestamp;
private DateTime dateTime;
public Timestamp getTimestamp() {
if (timestamp == null && dateTime != null) {
this.timestamp = new Timestamp(dateTime.getMillis());
}
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
if (dateTime == null && timestamp != null) {
this.dateTime = new DateTime(timestamp.getTime());
}
this.timestamp = timestamp;
}
public DateTime getDateTime() {
if (dateTime == null && timestamp != null) {
this.dateTime = new DateTime(timestamp.getTime());
}
return dateTime;
}
public void setDateTime(DateTime dateTime) {
if (timestamp == null && dateTime != null) {
this.timestamp = new Timestamp(dateTime.getMillis());
}
this.dateTime = dateTime;
}
}
외부 라이브러리를 프로젝트에 도입하는 경우 왜 [ThreeTen Backport] (http://www.threeten.org/threetenbp/)가 필요합니까? 이것에 의해, 최신의 Java 일자 및 시각 API 인'java.time'가 제공됩니다. Joda-Time 홈페이지의 인용문 : "사용자는 이제'java.time' (JSR-310)으로 마이그레이션하라는 요청을받습니다."Joda-Time은 크게 "완료된"프로젝트로 간주됩니다. 주요 개선 사항은 계획되지 않았습니다. Java SE 8을 사용하는 경우,'java.time' (JSR-310)로 마이그레이션하십시오. "Java 6 또는 7을 사용하는 경우에도 지금 바로 그 단계를 수행 할 수 있습니다. –