Java JSpinner.DateEditor 24小时
我有一个Java JSpinner.DateEditor 24小时,java,jspinner,Java,Jspinner,我有一个JSpinner和一个DateEditor,HH:mm看起来像这样: 是否可以同时显示24:00和00:00。基本上,我希望它像: 23:58,23:59,24:00,00:00,00:01,00:02 而不是 23:58,23:59,00:00,00:01,00:02 我尝试了@覆盖getNextValue()但似乎无法解决这个问题。有什么建议吗 public class SpinnerMain { public static void main(String[] args)
JSpinner
和一个DateEditor
,HH:mm
看起来像这样:
是否可以同时显示24:00
和00:00
。基本上,我希望它像:
23:58,23:59,24:00,00:00,00:01,00:02
而不是
23:58,23:59,00:00,00:01,00:02
我尝试了@覆盖getNextValue()
但似乎无法解决这个问题。有什么建议吗
public class SpinnerMain {
public static void main(String[] args) {
JSpinner s = new JSpinner(new SpinnerDateModel() {
boolean show24 = true;
@Override
public Object getNextValue() {
Calendar cal = Calendar.getInstance();
cal.setTime(getDate());
int field = getCalendarField();
// If the Spinner should show "24"
int min = cal.get(Calendar.MINUTE);
if (min == 0 && field == Calendar.MINUTE && show24) {
show24 = false;
// Change the display value ....
}
cal.add(field, 1);
Date next = cal.getTime();
return ((getEnd() == null) || (getEnd().compareTo(next) >= 0)) ? next
: null;
}
});
JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(s, "HH:mm");
s.setEditor(timeEditor);
Date d = new Date();
d.setTime(1000 * (22 * 3600) + 1000 * 59 * 60);
s.setValue(d);
JFrame frame = new JFrame();
frame.add(s);
frame.pack();
frame.setVisible(true);
}
}
因为,对我来说,00:00和24:00是不同的日子。也就是说,如果我只想选择一个特定的日期,我还需要给出该日期的时间00:00-24:00。现在我只能说00:00-23:59,这还不够好。如果我没弄错的话,24:00在日期和时间上与00:00完全相同。。。。。只是格式不同而已。