I have hibernate entity and a bean:
@Entity public class GeneralObservation { @DateTimeFormat(pattern = "dd/MM/yyyy") Date date; @Column public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } }
also I have
@InitBinder protected void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); binder.registerCustomEditor(Date.class, new CustomDateEditor( dateFormat, false)); }
and
form:input id = "datepicker" name="date" itemLabel="date" path="newObservation.date"
How can I force it to have mm/DD/yyyy format? Thanx
可以使用fmt:formatDate jstl标签:
<fmt:formatDate value="${yourObject.date}" var="dateString" pattern="dd/MM/yyyy" /> <form:input path="date" value="${dateString} .. />