Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Joda时间:格式无效。数据格式不正确_Java_Jodatime - Fatal编程技术网

Java Joda时间:格式无效。数据格式不正确

Java Joda时间:格式无效。数据格式不正确,java,jodatime,Java,Jodatime,正在尝试使用日期和时间处理此字符串: 2015-10-23T00:00:00+03:00 通过使用此代码: String transactionDateValue = getNodeValue(nodeList, i, "transactionDate"); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss ZZZ"); DateTime jodaTime = dateTim

正在尝试使用日期和时间处理此字符串:

2015-10-23T00:00:00+03:00
通过使用此代码:

String transactionDateValue = getNodeValue(nodeList, i, "transactionDate");
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss ZZZ");
DateTime jodaTime = dateTimeFormatter.parseDateTime(transactionDateValue);
DateTimeFormatter resultFormat = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss");
这就是错误:

java.lang.IllegalArgumentException: Invalid format: "2015-10-23T00:00:00+03:00" is malformed at "T00:00:00+03:00"

    at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945)
    at repgen.service.PrepareExcelService.fillContent(PrepareExcelService.java:169)
    at repgen.service.PrepareExcelService.prepareDocument(PrepareExcelService.java:44)
    at repgen.service.PrepareExcelServiceTest.testPrepareExcelService(PrepareExcelServiceTest.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.mockito.internal.junit.JUnitRule$1.evaluate(JUnitRule.java:16)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
    at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
我怀疑我的错误在ZZZ参数附近,但无法解决它。我还尝试了参数ZZZZ,ZZ,但没有解决它

您的格式必须是:

DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ");
它必须与日期字符串完全相同,固定值由单引号转义,并且没有额外的空格。
您还必须使用24小时格式的
HH
。hh是12小时格式,从1开始到12结束。这是因为您试图解析的字符串包含一个
T
,而该字符串不是格式字符串

您正在尝试解析标准格式的字符串。您不需要为此自定义日期格式字符串,因为Joda Time默认情况下已经支持此格式。只要做:

DateTime jodaTime = DateTime.parse(transactionDateValue);

这是因为您试图解析的字符串包含一个
T
,该字符串的格式不是字符串。顺便说一下,这是Joda Time已经支持的标准ISO-8601格式,您不需要使用自定义格式字符串。只需执行
DateTime jodaTime=DateTime.parse(transactionDateValue)谢谢!这很有魅力!尝试以下代码:DateTime jodaTime=DateTime.parse(“2015-10-23T00:00:00+03:00”);DateTimeFormatter resultFormat=DateTimeFormat.forPattern(“dd/MM/yyyy HH:MM:ss”);System.out.println(resultFormat.print(jodaTime));在编辑您的评论时编辑了以上评论。现在一切正常。谢谢这对我有用,谢谢!但是在我的例子中,我必须在“”之间加上我的Z,比如'Z'