我正在创建我的JSpinner。如果我不使用“dateSpinner.setEditor(new JSpinner.DateEditor(dateSpinner,”DD:MM:YYYY“));”,GUI工作正常,正确显示日期和时间,例如,12-2-13 11 :39。但如果我使用它,日期会出错,显示44/02/2012。有什么问题?谁能帮我吗?感谢。
private JPanel getTimePanel() {
JPanel centerPanel = new JPanel();
centerPanel.setBorder(BorderFactory.createTitledBorder("Calendar"));
GregorianCalendar cal = new GregorianCalendar();
Date initialDate = cal.getTime();
cal.add(Calendar.YEAR, -50);
Date earliestDate = cal.getTime();
cal.add(Calendar.YEAR, 100);
Date latestDate = cal.getTime();
SpinnerDateModel dateModel = new SpinnerDateModel(initialDate,
earliestDate,
latestDate,
Calendar.DATE);
JSpinner dateSpinner = new JSpinner(dateModel);
//dateSpinner.setEditor(new JSpinner.DateEditor(dateSpinner, "DD:MM:YYYY"));
// Add GUI components
centerPanel.add(dateSpinner);
return centerPanel;
}
答案 0 :(得分:3)
我猜你的格式字符串不正确。它应遵循SimpleDateFormat的惯例:"dd:MM:yyyy"