gpt4 book ai didi

Java DateTimeFormat 模式?

转载 作者:行者123 更新时间:2023-11-30 02:58:50 27 4
gpt4 key购买 nike

我需要有关日期格式的帮助,我看不到我缺少的内容。

格式:EEEE d'th' 'of' MMMM yyyy hh:mm:ss a
日期:2016 年 4 月 6 日星期三 06:10:08 AM尝试过here并且似乎有效。

有人有什么想法吗?

其他信息
- 使用 SimpleDateFormat
进行测试- 使用 Joda 时间 (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");
}

谢谢你的帮助

最佳答案

日/月/AM/PM 标记字段可能与您的默认区域设置不匹配(看起来像 French )

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

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com