1
偏移我已在下面的代碼段,其假定在JSpinner的對象以顯示時間JSpinner的表示時間具有恆定小時儘管正確值
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.AM_PM, 0);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
spStartTime = new JSpinner(new CustomSpinnerModel(cal.getTime(), null, null, cal.get(Calendar.HOUR_OF_DAY), 100, "start"));
((JSpinner.DefaultEditor) spStartTime.getEditor()).getTextField().setFormatterFactory(new DefaultFormatterFactory(new DateFormatter(new SimpleDateFormat("hh:mm:ss,SSS"))));
CustomSpinnerModel延伸SpinnerDateModel和我重寫getNextValue()和getPreviousValue() 。
public Object getNextValue()
{
Object next = super.getValue();
Calendar calendar = new GregorianCalendar();
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
calendar.setTime((Date) next);
Date helper = new Date(calendar.getTimeInMillis() + defaultStep);
calendar.setTime(helper);
System.out.println(calendar.getTimeInMillis());
return calendar.getTime();
}
現在這個打印100毫秒我第一次打上箭頭,這意味着值是正確的,因爲我開始0毫秒。問題是,我在JSpinner中看到的是
02:00:00,100
可視化中存在一個持續2小時的偏移量。
該訣竅。謝謝。 –