我在此網站上追蹤了其他幾個解決方案,並且沒有安裝Joda Time,但我仍然爲此感到失望。使用DateFormat.parse()的可解析日期
我也嘗試刪除冒號,如一個解決方案所述,但沒有幫助。
currentNode.getProperty("jcr:created").getString()
= 2013-03-07T11:57:08.596-05:00
我得到這個錯誤:java.text.ParseException:無法解析的日期:「2013-03-07T11:57:08.596 -05:00"
<%@page import="
java.util.Date,
java.text.SimpleDateFormat,
java.text.DateFormat"
%>
<%
DateFormat outputFormat = new SimpleDateFormat("MMMM dd, yyyy");
DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
String currentDate = currentNode.getProperty("jcr:created").getString();
Date date = inputFormat.parse(currentDate); // <-- Failing here
String currentDateString = outputFormat.format(date);
%>
相關:http://stackoverflow.com/a/2202300/738746 – 2013-03-19 17:20:56