[英]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.