怎么把Joda Localdate转换成Joda DateTime? [英] How to convert Joda Localdate to Joda DateTime?

查看:115
本文介绍了怎么把Joda Localdate转换成Joda DateTime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在执行更多计算之前将TimeZone信息简单地添加回LocalDate中. LocalDate来自使用ObjectLab LocalDateCalculator向现有的DateTime添加天数,但是该方法需要返回修改后的ReadableInstant来形成一个Interval,然后我可以检查该Interval.

I'm trying to simply add TimeZone information back into a LocalDate before performing some more calculations. The LocalDate came from using the ObjectLab LocalDateCalculator to add days to an existing DateTime but the method needs to return a modified ReadableInstant to form an Interval which I can then inspect.

我正在尝试的代码相当于将Joda LocalDate转换为Joda DateTime:

The code I'm trying amounts to a conversion of Joda LocalDate to Joda DateTime:

LocalDate contextLocalBusinessDate = calculator.getCurrentBusinessDate();
DateTime businessDateAsInContextLocation = new DateTime(contextLocalBusinessDate, contextTimeZone);

我收到的错误来自Joda的转换系统:

The error I get is from Joda's conversion system:

java.lang.IllegalArgumentException: No instant converter found for type: org.joda.time.LocalDate
        at org.joda.time.convert.ConverterManager.getInstantConverter(ConverterManager.java:165)
        at org.joda.time.base.BaseDateTime.<init>(BaseDateTime.java:147)
        at org.joda.time.DateTime.<init>(DateTime.java:192)

我正在寻找解决此问题的方法,或者是一种解决方法,它可以产生具有完整时区信息的准确间隔.

I'm looking for a fix to this problem, or a workaround that results in an accurate Interval with full timezone information.

推荐答案

There are various methods on LocalDate for this, including:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆