display seconds in DateTimeItem (SmartGWT)

拈花ヽ惹草 提交于 2019-12-11 16:53:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!