Spring mongo和Joda DateTime

时间:2014-07-25 14:18:21

标签: java spring jodatime

将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还需要什么?

由于

麦克

1 个答案:

答案 0 :(得分:1)

尝试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);