1

I need help with my date format, I can't see what I am missing.

Format : EEEE d'th' 'of' MMMM yyyy hh:mm:ss a
Date : Wednesday 6th of April 2016 06:10:08 AM Tryied here and seems to work.

Does someone have any idea ?

Additional infos
- Tested with SimpleDateFormat
- Tested with Joda time (DateTimeFormat) v2.1

EDIT :
Both solutions Ihave tried are not working. Here is the stack trace

java.lang.IllegalArgumentException: Invalid format: "Wednesday 6th of April 2016 06:1..."
    at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:866)
    at com.thales.communications.webintlab.ewr.spider.impl.PasteBinSpiderTest.lolTest(PasteBinSpiderTest.java:22)
    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 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)

EDIT 2 :
Unit test throwing the error :

@Test
    public void formatTest() throws ParseException {
        final DateTimeFormatter dtf = DateTimeFormat.forPattern("EEEE d'th of' MMMM yyyy hh:mm:ss a");

        dtf.parseDateTime("Wednesday 6th of April 2016 06:10:08 AM");
    }

Thanks for you help

7
  • 3
    what is the issue? Commented Apr 6, 2016 at 13:30
  • 6
    I can't wait for the 1th of May! Commented Apr 6, 2016 at 13:31
  • 1
    The ... in your String means it doesn't follow your format; it stops after 1. Commented Apr 6, 2016 at 13:33
  • 2
    How are you trying to parse that string?? I need to see the souce code! Commented Apr 6, 2016 at 13:33
  • 1
    Also don't forget to use the correct Locale, since you're working with words and they are locale dependent. Commented Apr 6, 2016 at 13:38

1 Answer 1

2

The day/month/AM/PM marker fields may not match those of your default Locale (Looks like French)

DateTimeFormatter dtf = 
        DateTimeFormat.forPattern("EEEE d ' of ' MMMM yyyy hh:mm:ss a").withLocale(Locale.US);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.