Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joda String DateTime to DateTime

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

like image 239
user2567005 Avatar asked May 21 '26 22:05

user2567005


1 Answers

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
like image 108
Rod_Algonquin Avatar answered May 24 '26 10:05

Rod_Algonquin