2012-03-27 33 views
0

我創建了一個幫助器來解析webservice的時間,並使用@DateTimeFormat以另一種格式輸出 。但在我的jsp視圖中,這沒有格式化。我使用這個錯誤嗎?Spring Java @DateTimeFormat

@Component 
public class DateParserHelper { 

    @DateTimeFormat(style="F-") 
    public Date getFormattedDate() { 
     return formattedDate; 
    } 


    public void setFormattedDate(Date formattedDate) { 

     this.formattedDate = formattedDate; 
    } 


    public Date formattedDate; 

    public void setDate(String date) throws ParseException { 

     DateFormatter dateFormatter = new DateFormatter("y-M-d"); 
     setFormattedDate(dateFormatter.parse(date, UK)); 

    } 





} 

回答

0

如果你在你的JSP使用JSTL,你可以使用formatDate來格式化日期:

<fmt:formatDate value="${yourDate}" pattern="dd/MM/yyyy" /> 
+0

我寧願日期以特定格式呈現給視圖。但我會感謝它。 – 2012-03-27 09:06:43

+0

仍然無法獲得@dateTimeFormat工作,我去了這個謝謝 – 2012-03-28 13:36:42

0

嘗試SimpleDateFormat

String pattern = "MM/dd/yyyy"; 

... 

public void setDate(String date) { 
    SimpleDateFormat format = new SimpleDateFormat(pattern); 
    setFormattedDate(format.parse(date)); 
} 
+0

謝謝 - 我希望能保持彈簧的東西雖然我知道SimpleDateFORMAT – 2012-03-27 09:05:38