如何将日期格式的 JSpinner 值存储到 JodaTime 变量中?

发布于 2025-01-04 18:51:09 字数 266 浏览 2 评论 0原文

我有一个自定义类,其中包含 JodaTime 的 LocalDate 变量来保存日期。 我的 swing 应用程序有一个带日期模型的 JSpinner。 我创建了一个按钮单击事件,以便将日期存储在对象的 LocalDate 数据成员内。 问题是编译器给了我 IllegalArgumentException。

我尝试使用 LocalDate.parse(spinnerDate.getVALue().toString()) 但不起作用。 还尝试切换到使用 DateTime 类型,但给出了相同的结果。

I got a custom class that contains JodaTime's LocalDate variable to hold a date.
My swing application has a JSpinner with Date model.
I made a button click event so that the date gets stored inside an object's LocalDate data member.
Problem is compiler gives me the IllegalArgumentException.

I tried to use LocalDate.parse(spinnerDate.getVAlue().toString()) but is not working.
Also tried to switch to using DateTime type but same result was given.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡尘雨 2025-01-11 18:51:09

鉴于 IllegalArgumentException 是在运行时生成的,我怀疑您遇到了“编译器”错误。

如果您不关心时区或年表(可能),您始终可以使用 new LocalDate(spinnerDate.getValue());。

否则,请考虑实现您自己的可以本地存储 LocalDate 的微调器,或者切换到使用 SpinnerListModel 中预定义的 LocalDate 列表。 。

Given that an IllegalArgumentException is something that would be generated at runtime, I doubt you're getting a 'compiler' error.

If you don't care what the timezone or chronology is (probable), you could always use new LocalDate(spinnerDate.getValue());.

Otherwise, consider implementing your own spinner that can store LocalDates natively, or switching to using a pre-defined list of LocalDates in a SpinnerListModel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文