首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring mongo和Joda DateTime

Spring mongo和Joda DateTime
EN

Stack Overflow用户
提问于 2014-07-25 22:18:21
回答 1查看 1.1K关注 0票数 1

在将Long类型转换为Joda DateTime类型时,我遇到了这个异常。

代码语言:javascript
复制
org.springframework.core.convert.ConverterNotFoundException:
    No converter found capable of converting from type java.lang.Long
    to type org.joda.time.DateTime

我正在使用

代码语言:javascript
复制
        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吗?

谢谢

麦克

EN

回答 1

Stack Overflow用户

发布于 2014-07-25 22:48:50

尝试DateTime(长时间即时)路线。如果需要格式化,请尝试将长整型转换为字符串,然后使用DateTimeFormatter:

代码语言:javascript
复制
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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24957882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档