Joda Time: format non Valide. De données est incorrect
D'essayer de traiter cette chaîne avec la date et l'heure:
2015-10-23T00:00:00+03:00
En utilisant ce code:
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");
C'est l'erreur:
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)
Je soupçonne mon erreur est proche de la ZZZ paramètre, mais ne peut pas le résoudre. J'ai aussi essayé les paramètres ZZZZ, ZZ, mais qui n'ont pas le fixer.
C'est parce que la chaîne que vous essayez d'analyser contient un
Merci! Cela a fonctionné comme un charme!
Essayez ce code : DateTime jodaTime = DateTime.parse("2015-10-23T00:00:00+03:00"); DateTimeFormatter resultFormat = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss"); System..println(resultFormat.print(jodaTime));
T
qui n'est pas dans la chaîne de format. Par la voie, c'est la norme ISO-8601 qui Joda Time prend déjà en charge, vous n'avez pas besoin d'utiliser une chaîne de format personnalisée. Il suffit de ne DateTime jodaTime = DateTime.parse(transactionDateValue);
Merci! Cela a fonctionné comme un charme!
Essayez ce code : DateTime jodaTime = DateTime.parse("2015-10-23T00:00:00+03:00"); DateTimeFormatter resultFormat = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss"); System..println(resultFormat.print(jodaTime));
OriginalL'auteur Deniss M. | 2016-10-12
Vous devez vous connecter pour publier un commentaire.
Cela se produit parce que la chaîne que vous essayez d'analyser contient un
T
, ce qui n'est pas dans la chaîne de format.Vous essayez d'analyser une chaîne de caractères qui est dans la norme des ISO 8601 format. Vous n'avez pas besoin d'un format de date personnalisé chaîne pour cela, parce que Joda Temps déjà prend en charge ce format par défaut. Il suffit de ne:
OriginalL'auteur Jesper
Votre Format doit être:
Il doit être exactement comme la chaîne de date, avec les valeurs fixes échappé par des guillemets simples et sans espaces.
Aussi, vous devez utiliser
HH
pour le Format de 24 heures. hh est de 12 heures Format et il commence à 1 et se Termine le 12OriginalL'auteur Jens