문제

I'd like to only use the time for my model, to define when in the day the event is going to occur, but the only way I found was to do this :

@Temporal(TemporalType.TIME)
public Date end;

But I'd like to have in my database, a type TIME which is exactly what I'm looking for.

How can I do that?

Thanks for your help!

도움이 되었습니까?

해결책

You can use java.sql.Time, but be careful - it has other definition than MySQL TIME column type - it operates only in range 00:00:00 - 23:59:59 (although MySQL allows you to store intervals -/+ 838 hours)

model:

public Time end;

set with:

event.end = Time.valueOf("12:15:00");

Anyway maybe it's safer to store the time/interval as a string or integer (of minutes)?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top