问题
when reading SmartGWT DateTimeItem: accept 12 hour format I found that using TimeDisplayFormat
offers the options to display the seconds as, e.g. dateTimeItem.setTimeFormatter(TimeDisplayFormat.TOPADDED24HOURTIME);
well, but there was no change in the displaying of the date.
As the code states that TimeDisplayFormat
is deprecated, and one should use the DateDisplayFormatter
instead, I tried dateTimeItem.setDateFormatter(DateDisplayFormat.TOSERIALIZEABLEDATE);
, but still no change.
The value gets set via dateTimeItem.setValue(myDate);
Any idea what (else) I have to set to the DateTimeItem
in order to get the seconds displayed as well?
I'm using SmartGWT 3.1
PS: I tried dateTimeItem.setDisplayFormat(DateDisplayFormat.TOSERIALIZEABLEDATE);
as well, but still no change
回答1:
It seems DateDisplayFormat.TOSERIALIZEABLEDATE
is having some issue in SmartGWT 3.x.
dateTimeItem.setDateFormatter(DateDisplayFormat.TOSERIALIZEABLEDATE);
works correctly in SmartGWT 4.0.
dateTimeItem.setDisplayFormat(DateDisplayFormat.TOSERIALIZEABLEDATE);
did not provide required behavior even in 4.0, probably due to a default system wide format setting.
You should be able to use a value formatter as a workaround in 3.0.
dateTimeItem.setEditorValueFormatter(new FormItemValueFormatter() {
public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
if (value != null && value instanceof Date) {
return DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").format((Date) value);
}
return null;
}
});
Check DateItem.setEditorValueFormatter as you might have to set input format, etc. as well.
回答2:
hi use the following code in your dateitem timeSheetDate.setShowPickerTimeItem(true); timeSheetDate.setTimeFormatter(TimeDisplayFormat.TOSHORTTIME); and also you can use timeSheetDate.setTimeFormatter(TimeDisplayFormat.TOTIME);
来源:https://stackoverflow.com/questions/17613892/display-seconds-in-datetimeitem-smartgwt