Hibernate - time format annotation
-
29-06-2021 - |
Question
I've in DB (mysql) a column type format time e.g. 12:30:00 I use for column in Hibernate domain the follow code
private LocalTime timeStart;
@Type(type="org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime")
@Column(name="time_start")
public LocalTime getTimeStart(){
return timeStart;
}
If I print the value I have 12:00:00.000 Can I have directly the pattern hh:mm without string trasformation,If yes How? TNX...
Solution
public LocalTime getTimeStart(){
return timeStart;
}
public String getTimeStartAsString(){
return timeStart == null ? "" : timeStart.toString("hh:mm");
}
OTHER TIPS
You need to use a DateTimeFormat instance to format a date object from Joda Time:
DateTimeFormat.forPattern("hh:mm").print( timeStart );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow