I want to convert my input into a timestamp value.
I have only found a dateconverter in examples. Are there any best practises?
Thank you
Update:
I want to save a birthday of a user but my backend requires a timestamp value. And I have problems with binding it to my jsf frontend..
Maybe a link to an example would be helful 🙂
I tried it as follows:
public void setBday(Date bday) {
member.setBirthday(new Timestamp(bday.getTime()));
}
public Timestamp getBday() {
return member.getBirthday();
}
But I get exceptions (strange):
/createMember.xhtml @34,54 value="#{member.bday}": Cannot convert 13.01.83 01:00 of type class java.util.Date to class java.sql.Timestamp
(Is it maybe because of get method?)
Bind to
Date#getTime()instead to get/set the raw timestamp in milliseconds.Or if you want to input/output a human readable date, then just stick to using
#{bean.date}and use the standard date converters.In the backend just use
Date#getTime()to process the timestamp.Update: you shouldn’t clutter your model with JDBC specific API. The
java.util.Daterepresents the timestamp. Usejava.sql.Timestamponly at that point you’re about to persist ajava.util.Datein aTIMESTAMPorDATETIMEcolumn of your DB.