我需要日期格式方面的帮助,我看不到我所缺少的内容。

格式:EEEE d'th' 'of' MMMM yyyy hh:mm:ss a
日期:Wednesday 6th of April 2016 06:10:08 AM
尝试here并似乎可以工作。

有人有什么主意吗?

其他资讯
-用SimpleDateFormat测试
-已通过Joda time (DateTimeFormat) v2.1测试

编辑:
我尝试过的两个解决方案都无法正常工作。
这是堆栈跟踪

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)


编辑2:
单元测试抛出错误:

@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");
    }


谢谢你的帮助

最佳答案

日期/月份/上午/下午标记字段可能与默认语言环境的字段不匹配(看起来像French

DateTimeFormatter dtf =
        DateTimeFormat.forPattern("EEEE d ' of ' MMMM yyyy hh:mm:ss a").withLocale(Locale.US);

关于java - Java DateTimeFormat模式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36452590/

10-12 15:21