質問

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