Unmatched date using DateFormat.parse ()

I took advantage of several other solutions on this site for this dilemma, and I don't have Joda Time installed, but I still don't understand why this is happening.

I also tried to remove the colons, as indicated in one of the solutions, but this did not help.

currentNode.getProperty("jcr:created").getString()= 2013-03-07T11: 57: 08.596-05: 00

I get this error: java.text.ParseException: Unmatched date: "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);
%>
+5
source share
3 answers

A time zone shaped like Zit should be -0500, not -05:00.

Therefore, I suggest you replace

DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

with

DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");

. SimpleDateFormat javadoc.

jdk X, , :. :

currentDate = currentDate.replaceAll(":(\\d\\d)$", "$1")
+12

, , -0530 (India).

, :

DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");

XX , .

+1

, , , "MMMM dd, yyyy".

getDate() Property, Calendar, getTime().

, , , .

<%@ page import="java.util.Calendar,
    java.text.SimpleDateFormat,
    java.text.DateFormat" %>
<%
DateFormat outputFormat = new SimpleDateFormat("MMMM dd, yyyy");
Calendar currentDate = currentNode.getProperty("jcr:created").getDate();
String currentDateString = outputFormat.format(currentDate.getTime()); %>

Thus, this eliminates the need to convert the string to Date and then perform the remaining operations. Hope this helps.

0
source

All Articles