在 JCalendar 中使用 JDateChooser 获取不需要的数据
我在 JCalendar
(使用 Swing)中使用 JDateChooser。我试图获取“yyyy-MM-dd”的格式,但由于某种原因,我也得到了时间,而且它总是相同的(00:00:00 MDT)。有人知道如何摆脱时间吗? 提前致谢。
try {
calendarDate = new JDateChooser();
} catch (Exception e) {
e.printStackTrace();
}
calendarDate.setDateFormatString("yyyy-MM-dd");
dateLabel = new JLabel("Date");
parent.frame2.getContentPane().add(dateLabel);//1
parent.frame2.getContentPane().add(calendarDate);
I am using JDateChooser in JCalendar
(with Swing). I am trying to get a format of "yyyy-MM-dd", but for some reason I get the time also and it's always the same(00:00:00 MDT). Anyone has an idea how to get rid of the time?
Thanks in advance.
try {
calendarDate = new JDateChooser();
} catch (Exception e) {
e.printStackTrace();
}
calendarDate.setDateFormatString("yyyy-MM-dd");
dateLabel = new JLabel("Date");
parent.frame2.getContentPane().add(dateLabel);//1
parent.frame2.getContentPane().add(calendarDate);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要让
JDateChooser
显示特定的日期格式,您需要使用其setDateFormatString
API 设置该特定格式 示例:
您已经在使用 gthis 了吗?然后,您必须发布从组件中获取价值的位置。
在处理 JDateChooser 属性更改的地方,您可以执行类似以下操作来获取相同格式的日期:
示例:(假设 String dateString 是您想要日期字符串的位置)
To get
JDateChooser
to show a specific date format, you need to set that specific format using itssetDateFormatString
APIExample :
Are you already doing gthis ? Then you must post the place where you are getting value from the component.
And in the place where you handle property change of JDateChooser, you may do something like the following to get the date in same format :
Example: (assuming String dateString is where you want the date string)
我使用代码源,而不是 *.jar 中的编译文件,然后
I'm use code source, not compiled file in the *.jar, then
请注意 JDateChososer 文本字段中日期标记的格式。您可能犯的一个常见词汇错误如下我假设 JDateChooser 后面有一个
addPropertyChangeListener
来捕获用户在输入中设置的日期:在脚本中,它被错误地编写为:
当您选择年份的格式模式时“ YYYY”(而不是“yyyy”或“yy”cfr API)无法识别并生成如下失败:当您尝试编辑 JDateChooser 的文本字段时当鼠标离开时,日期会自动更改为随机值。已经不能再改变了。这也可能会产生不需要的日期。
Please, make attention in formatting the stamp of the date in the JDateChososer textField. A common lexical mistake you can do is the following I supposed a
addPropertyChangeListener
behind the JDateChooser to catch the date user sets in input:In the script it has been wrongly written:
When you choose the year's format pattern "YYYY" (instead of "yyyy" or "yy" cfr API) it is not recognized and generates a failure as follows: when you try editing the JDateChooser's textfield and you make a mouse step-off, the date automatically changed in a random value. It can't be changed anymore. That could generate an unwanted date as well.