是否可以在Spring MVC控制器中處理不同的日期格式?如何在Spring MVC控制器中處理不同的日期格式?
我知道,設定這樣的事情
@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, false));
}
我可以處理dd/MM/yyyy
格式,但如果我要分析什麼也日期在yyyyMMddhhmmss
格式?我應該在控制器中添加多個CustomDateEditor
嗎?
強制在客戶端只有一個日期格式也一樣,jQuery UI的日期選擇器等可以很容易 – NimChimpsky
這是相當奇怪 - 我明白,你可以*解析*不同格式的日期與自定義編輯器或甚至更好的類型轉換器 - 但你將如何*顯示*他們?它認爲你應該實現你自己的日期類型來封裝關於它的表示的信息,看起來有點奇怪 –
我認爲它應該以相同的格式表示,否則你會遇到問題。在這裏,你只有一個格式化程序,只有一種格式,如果你有多個格式,它應該採取第一個有效的格式, – EliuX