如何将日期格式的 JSpinner 值存储到 JodaTime 变量中?
我有一个自定义类,其中包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于
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
LocalDate
s natively, or switching to using a pre-defined list ofLocalDate
s in aSpinnerListModel
.