[英]Get jDateChooser date to jLabel
This is my infernal problem. 这是我的地狱问题。 nowadays i'm trying to create my project according to my Degree.
如今,我正在尝试根据我的学位创建我的项目。 I already have added jcalender to my project in netbeans, and i already added jDateChooser to my jFrame.
我已经将jcalender添加到了netbeans项目中,并且已经将jDateChooser添加到了jFrame中。 my problem is, when i chooseing a date from jDateChooser how will display this date on a jLabel.
我的问题是,当我从jDateChooser选择日期时,如何在jLabel上显示该日期。 i tried to using
jLabel1.setText(jDateChooser1);
我试图使用
jLabel1.setText(jDateChooser1);
but in this case error will occur. 但是在这种情况下会发生错误。 http://imgur.com/nMa9JMw
http://imgur.com/nMa9JMw
First, you need to get the date from the component, something like... 首先,您需要从组件获取日期,例如...
Date date = jDateChooser1.getDate();
Next you need to format that Date
value to a String
接下来,您需要将该
Date
值格式化为String
String strDate = DateFormat.getDateInstance().format(date);
Finally, you need to set that value as the text for the lable... 最后,您需要将该值设置为标签的文本...
jLabel1.setText(strDate);
If you have particular formatting requirements, you may need to look at SimpleDateFormat
如果您有特殊的格式要求,则可能需要查看
SimpleDateFormat
String date = ((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText();
jLabel1.setText(date);
Try this, 尝试这个,
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = sdf.format(jDateChooser1.getSelectedDate().getTime());
jLabel1.setText(date);
import this file>> 导入此文件>>
import java.text.SimpleDateFormat;
Try this code >> 尝试此代码>>
SimpleDateFormat dcn = new SimpleDateFormat("yyyy-MM-dd");
String date = dcn.format(jDateChooser1.getDate() );
jLabel1.setText(date.toString());
Try this: 尝试这个:
String date1 = ((JTextField) jDateChooser4.getDateEditor().getUiComponent()).getText() + "";
jLabel1.setText(date1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.