24h problems in convertDateTime in JSF
converters, jsf, time
Solution
The `<f:convertDateTime>` uses `java.text.SimpleDateFormat` API under the covers, whose javadoc is available here, listing all available pattern letters.
For hours, you used a pattern of `hh` which is in the javadoc described as
h Hour in am/pm (1-12)
, while you clearly want the one described as follows in the javadoc:
H Hour in day (0-23)
Fix it accordingly:
<f:convertDateTime type="time" pattern="HH:mm" timeZone="#{backBean.timeZone}"/>
Problem
I have an input textfield with a convertDateTime to see if the time is right. The problem is that convertDateTime is set to 12 hours of counting but I want 24 hours of counting, someone who knows how to solve this? If for example, I type in 14:12, I get the error message: '14: 12 'could not be under stood as a date. But 02:12 is fine. Here is the code: ``` <h:outputText value="Time"/> <h:inputText value="#{backBean.time}" > <f:convertDateTime type="time" pattern="hh:mm" timeZone="#{backBean.timeZone}"/> </h:inputText> ``` Backbean: ``` @ManagedBean(name = "backBean") @SessionScoped public class BackBean { private Date date = new Date(); public void setTime(Date inDate) { date.setMinutes(inDate.getMinutes()); date.setHours(inDate.getHours()); } public Date getTime() { return date; } public TimeZone getTimeZone() { TimeZone timeZone = TimeZone.getDefault(); return timeZone; } } ```