Created
December 23, 2017 21:18
-
-
Save Wicowyn/9198567c2de865107bd4f75f9c6aa455 to your computer and use it in GitHub Desktop.
JPA Joda DateTime converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DateTimeConverter implements AttributeConverter<DateTime, Date> { | |
@Override | |
public Date convertToDatabaseColumn(DateTime attribute) { | |
return attribute == null ? null: new Date(attribute | |
.withZone(DateTimeZone.UTC) | |
.withZoneRetainFields(DateTimeZone.getDefault()) | |
.getMillis()); | |
} | |
@Override | |
public DateTime convertToEntityAttribute(Date dbData) { | |
return dbData == null ? null | |
: new DateTime(dbData.getTime()) | |
.withZoneRetainFields(DateTimeZone.UTC) | |
.withZone(DateTimeZone.getDefault()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment