Unable to parse DateTime - Illegal moment due to transition with time zone offset (Europe / Berlin)

Why can't I make out the next date?

DateTime.parse("2015-03-29 02:35:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")); 

Result:

 org.joda.time.IllegalInstantException: Cannot parse "2015-03-29 02:35:00": Illegal instant due to time zone offset transition (Europe/Berlin) at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:471) at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:411) at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:882) at org.joda.time.DateTime.parse(DateTime.java:160) at Testasd.test(Testasd.java:9) 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:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

What is the problem? If I change the year to 2014-03-29 02:35:00 , it will work!

+6
source share
1 answer

As shown in the link :

Joda-Time allows key classes to store the correct date-time. For example, February 31 is not a valid date, so it cannot be saved (except for Partial). The same valid date-time principle applies to daylight saving time (DST). In many places, DST is used, where the local clock moves forward an hour in spring and back an hour in autumn / fall. This means that in spring there is a โ€œspaceโ€ where local time does not exist. The error "Illegal moment due to time zone offset" means this space. This means that your application tried to create a date-time between - a time that did not exist. Since Joda-Time objects must be valid, this is not permitted.

You refer to a date and time that does not exist due to a change in daylight saving time.

The solution is to use parseLocalDateTime .

+12
source

Source: https://habr.com/ru/post/976152/


All Articles