简体   繁体   English

找不到类型的即时转换器:java.time.ZonedDateTime

[英]No instant converter found for type: java.time.ZonedDateTime

I'm trying to fetch lower/upper endpoint from range and when it comes to fetch these lower/upper Endpoints it throws exception which goes like this:我正在尝试从范围中获取下/上端点,当涉及到获取这些下/上端点时,它会抛出异常,如下所示:

java.lang.IllegalArgumentException: No instant converter found for type: java.time.ZonedDateTime

    at org.joda.time.convert.ConverterManager.getInstantConverter(ConverterManager.java:166)
    at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:171)
    at org.joda.time.DateTime.<init>(DateTime.java:257)

The code:编码:

@Override
    public WeatherStatus getForecastForFlightOverall(String icao, ... flight) {

       ...

        if ( flightmapIntegration.isMetIntegrationEnabled() ) {
            List<ViewFlightAirportDTO> airports = getRoutes(icao, flight);
            Range<ZonedDateTime> range = getRange(airports);

            DateTime from = range.lowerEndpoint() == null ? null : new DateTime(range.lowerEndpoint());
            ...

            try {
               ....
            }
        }

        return status != null ? status : WeatherStatus.UNKNOWN;
    }

getRange method:获取范围方法:

 private Range<ZonedDateTime> getRange(List<...> ...) {

        if ( ....isEmpty() ) {
            return Range.singleton(ZonedDateTime.now());
        }

        Range<ZonedDateTime> result = validityRangeOf(....get(0));

        for (int i = 1; i < flightAirports.size(); i++) {
            result = ...
        }

        return result;
    }

validtyRangeOf method: validtyRangeOf 方法:

private Range<ZonedDateTime> validityRangeOf(ViewFlightAirportDTO firstAirport) {
        return Range.closed(firstAirport.getValidFrom(), firstAirport.getValidTill());
    }

EDIT I can make like this, but do not know how to finish it.编辑我可以这样做,但不知道如何完成。 I mean from/to can be also type of ZonedDateTime but I do not know how to create object of it with lower/upper Endpoint我的意思是 from/to 也可以是 ZonedDateTime 的类型,但我不知道如何使用下/上端点创建它的对象

   ZonedDateTime from = range.lowerEndpoint() == null ? null : new ZonedDateTime(...);
            ZonedDateTime to = ...

You are currently trying to convert from ZonedDateTime to DateTime by calling the constructor directly.您当前正在尝试通过直接调用构造函数将ZonedDateTime转换为DateTime

ZonedDateTime zonedDateTime = ZonedDateTime.now();
DateTime dateTime = new DateTime(zonedDateTime); // will cause IllegalArgumentException

You need to call a different constructor to make this conversion:您需要调用不同的构造函数来进行此转换:

DateTimeZone dateTimeZone = DateTimeZone.forID(zonedDateTime.getZone().getId()); // extract DateTimeZone separately
new DateTime(zonedDateTime.toInstant().toEpochMilli(), dateTimeZone); // convert using epoch milliseconds

This will allow you to do this conversion.这将允许您进行此转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 春季启动2:ConverterNotFoundException:未找到能够从类型[java.time.ZonedDateTime]转换为类型[java.util.Date]的转换器 - Spring boot 2 : ConverterNotFoundException: No converter found capable of converting from type [java.time.ZonedDateTime] to type [java.util.Date] 用于java.time.ZonedDateTime的MySQL类型 - What MySQL type to use for java.time.ZonedDateTime 将字符串转换为 java.time.ZonedDateTime - Convert String into java.time.ZonedDateTime 如何将java.time.ZonedDateTime转换为XMLGregorianCalendar? - How to convert java.time.ZonedDateTime to XMLGregorianCalendar? java.time.ZonedDateTime不能在android Studio中导入 - java.time.ZonedDateTime not import in android Studio 从Calendar week到java.time.ZonedDateTime - from Calendar week to java.time.ZonedDateTime 在实体类java.time.ZonedDateTime上找不到属性null以将构造函数参数绑定到 - No property null found on entity class java.time.ZonedDateTime to bind constructor parameter to 无法找到匹配的构造函数:java.time.ZonedDateTime() - unable to find matching constructor for: java.time.ZonedDateTime() java.time.ZonedDateTime 不支持将 Drools Fusion 转换为 long - Drools Fusion Conversion to long not supported from java.time.ZonedDateTime 使用休眠PostgreSQL无法存储java.time.ZonedDateTime - Failed to store java.time.ZonedDateTime using hibernate PostgreSQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM