如何从JCalendar获取JMonthChooser上的字符串月份名称
问题描述:
如何从JCalendar
(toedter.com/jcalendar/)获取JMonthChooser
字符串中的月份名称并将其转换为字符串“01”,“02”,“03”, ...,“12”就像使用SimpleDateFormat
一样简单。如何从JCalendar获取JMonthChooser上的字符串月份名称
我会尝试:
String mymonth;
SimpleDateFormat sdfm = new SimpleDateFormat("MM");
JComboBox combom = (JComboBox)jMonthChooser1.getSpinner();
mymonth = sdfm.format(((JTextField)combom.getEditor()).getText());
但没有成功
答
我有其他的方式,我需要什么: 这里是代码:
JCalendar jCalendar1 = new JCalendar();
String mymonth;
SimpleDateFormat sdf1 = new SimpleDateFormat("MM");
Date date1 = jCalendar1.getDate();
mymonth = sdf1.format(date1);
答
鉴于JMonthChooser
一个实例,一个PropertyChangeListener
将范围0 .. 11
看到Integer
类型的新价值。不要试图将其强制为适合SimpleDateFormat
的日期,请考虑使用合适的Formatter
。
JMonthChooser jmc = new JMonthChooser();
jmc.addPropertyChangeListener("month", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
System.out.println(e.getPropertyName() + ": "
+ String.format("%02d", ((Integer) e.getNewValue()).intValue() + 1));
}
});
发生了什么事'JMonthChooser'? – trashgod
我的主要目标是从JCalendar中找到月份的名称和格式字符串“01”,“02”,...,“12”中的索引。我很困惑,我想早些时候使用JMonthChooser。但是,然后我可以得到连续的月份和索引名称使用JCalendar。 我使用的月份的名称: String mymonth; SimpleDateFormat sdf1 = new SimpleDateFormat(“MMMM”); 日期date1 = jCalendar1.getDate(); mymonth = sdf1.format(date1); Bantuan Anda sangat saya apresiasi。 Terima kasih。 – repot
你想要的Locale不支持? – trashgod