im trying to convert a DateTime string that is passed like below
"2013-08-14T12:54:57.908+05:30"
my converter Function look like this
public static DateTime stringDateToJodaDateTime(String strDate){
DateTimeFormatter formatter = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss Z");
DateTime jodaDateTime = formatter.parseDateTime(strDate);
return jodaDateTime;
}
it gives me the below Error
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
... 88 more
Caused by: java.lang.IllegalArgumentException: Invalid format: "2013-08-14T12:54:57.908+05:30"
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:899)
at com.kpowd.utility.UserUtility.stringDateToJodaDateTime(UserUtility.java:65)
at com.kpowd.controller.CommonChartController.init(CommonChartController.java:51)
... 93 more
which i think because of the wrong "forPattern", i cannot change the string DateTime Pattern that is passed. all i can do is change the "DateTimeFormat.forPattern", help me
problem:
DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss Z")
That basically a wrong pattern for parsing your String date thus catching Invalid format upon parsing it.
solution:
yyyy-MM-dd'T'HH:mm:ss.SSSZ
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With