我有 hibernate 实体和一个 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;
}
}
我也有
@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, false));
}
和
form:input
id = "datepicker"
name="date"
itemLabel="date"
path="newObservation.date"
当我转到我的网址时,我看到:
如何强制它具有 mm/DD/yyyy 格式?谢谢
最佳答案
你可以使用 fmt:formatDate jSTL 标签:
<fmt:formatDate value="${yourObject.date}" var="dateString" pattern="dd/MM/yyyy" />
<form:input path="date" value="${dateString} .. />
关于java - spring mvc 日期格式,格式为 :input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18163404/