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...

有帮助吗?

解决方案

public LocalTime getTimeStart(){
      return timeStart;
}   

public String getTimeStartAsString(){
      return timeStart == null ? "" : timeStart.toString("hh:mm");
} 

其他提示

You need to use a DateTimeFormat instance to format a date object from Joda Time:

DateTimeFormat.forPattern("hh:mm").print( timeStart );
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top