gpt4 book ai didi

java - Spring mongo 和 Joda DateTime

转载 作者:太空宇宙 更新时间:2023-11-04 06:38:47 24 4
gpt4 key购买 nike

将 Long 转换为 Joda DateTime 时出现此异常。

org.springframework.core.convert.ConverterNotFoundException:
No converter found capable of converting from type java.lang.Long
to type org.joda.time.DateTime

我正在使用

        artifactId>spring-core</artifactId>
<version>4.0.3.RELEASE</version>

<artifactId>spring-integration-core</artifactId>
<version>4.0.3.RELEASE</version>

<artifactId>spring-integration-mongodb</artifactId>
<version>4.0.3.RELEASE</version>

<artifactId>spring-integration-mail</artifactId>
<version>4.0.3.RELEASE</version>


<artifactId>spring-messaging</artifactId>
<version>4.0.3.RELEASE</version>

<artifactId>spring-integration-xml</artifactId>
<version>4.0.3.RELEASE</version>

<artifactId>json-path</artifactId>
<version>0.9.1</version>

<artifactId>spring-data-commons-core</artifactId>
<version>1.4.0.RELEASE</version>

<artifactId>spring-data-commons</artifactId>
<version>1.8.1.RELEASE</version>

有谁知道我还需要什么才能将 Long 转换为 DateTime?

谢谢

迈克

最佳答案

尝试 DateTime(长即时)路线。如果需要格式化,请尝试将 long 转换为 String,然后使用 DateTimeFormatter:

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

long abc; //assign some value to this long
String s = String.valueOf(abc); //convert long to string
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.S"); ///modify this according to your needs
DateTime dt = formatter.parseDateTime(date);

关于java - Spring mongo 和 Joda DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24957882/

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