简体   繁体   English

Joda String DateTime to DateTime

[英]Joda String DateTime to DateTime

im trying to convert a DateTime string that is passed like below 我试图转换像下面传递的DateTime字符串

"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. 我认为因为错误的“forPattern”,我无法更改传递的字符串DateTime Pattern。 all i can do is change the "DateTimeFormat.forPattern", help me 我所能做的就是改变“DateTimeFormat.forPattern”,帮助我

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. 这基本上是一个错误的模式,用于解析您的String date从而在解析它时捕获Invalid format

solution: 解:

yyyy-MM-dd'T'HH:mm:ss.SSSZ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM