JSF Converter Timestamp

I want to convert my input to a timestamp value.

In the examples, I found only a date converter. Are there any better methods?

thanks


Update:

I want to keep the user's birthday, but my backend requires a timestamp. And I have problems binding to my jsf interface ..

Perhaps the link to the example would be helful :-)

I tried this as follows:

public void setBday(Date bday) { member.setBirthday(new Timestamp(bday.getTime())); } public Timestamp getBday() { return member.getBirthday(); } 

But I get exceptions (weird):

 /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 

(Perhaps this is due to the get method?)

+4
source share
1 answer

Bind Date#getTime() instead to get / set the raw timestamp in milliseconds.

 <h:inputText value="#{bean.date.time}" /> 

Or, if you want to enter / display a human-readable date, just stick to #{bean.date} and use standard date converters.

 <h:inputText value="#{bean.date}"> <f:convertDateTime type="date" dateType="short" /> </h:inputText> 

In the backend, just use Date#getTime() to handle the timestamp.


Update : you should not clutter your model with the JDBC specification. java.util.Date represents a timestamp. Use java.sql.Timestamp only when you are going to save java.util.Date in the TIMESTAMP or DATETIME column of your database.

 preparedStatement.setTimestamp(index, new Timestamp(bean.getDate().getTime())); 
+5
source

Source: https://habr.com/ru/post/1334814/


All Articles