2014-06-15 50 views
1

我有一個類型爲DATE的字段的數據庫表,我想用這種格式'dd.mm.yyyy hh:mm:ss'在用戶界面上顯示它。我得到它使用休眠查詢和轉換它使用:f:convertDateTime返回錯誤的日期和時間

<f:convertDateTime pattern="dd.mm.yyyy hh:mm:ss" /> 

但結果不是我所期望的。

例如:

8.6.2014 03:00:00 (from the DB) -> 08.00.2014 12:00:00 (in the user interface) 
15.6.2014 12:00:00 (from the DB) -> 15.00.2014 12:00:00 (in the user interface) 

我在web.xml中添加

<context-param> 
     <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name> 
     <param-value>true</param-value> 
    </context-param> 

我的時區爲UTC + 02:00

在此先感謝您的幫助。

回答

3

月份以大寫「M」表示。對你來說,這將是:

<f:convertDateTime pattern="dd.MM.yyyy HH:mm:ss" /> 

編輯

您應該添加你的時區太:

<f:convertDateTime pattern="dd.MM.yyyy HH:mm:ss" timeZone="GMT+2" /> 

EDIT 2

如果它不工作,您可以使用SimpleDateFormat

public static String dateToString(Date date, String format) throws ParseException { 
    SimpleDateFormat sdf = new java.text.SimpleDateFormat(format); 
    return sdf.format(date); 
} 

然後:

String newDate = dateToString(myDate, "dd.MM.yyyy HH:mm:ss"); 
+0

不它表明:2014年8月6日3點00分00秒(從DB) - > 2014年6月8日12時00分00秒(12:00:00總是O」時鐘) – Tot

+0

現在顯示09:00:00沒有改變任何東西。 – Tot

+0

你試過什麼模式? – Genzotto