i use DateItem, i want to display the date in text field as "MM/DD/YY" format, but it is not included in DateDisplayFormat enum, how can i customize the date display format for DateItem??
Announcement
Collapse
No announcement yet.
X
-
it seems the DateUtil can help,
original code:
Code:firstDateChoice = new DateItem(); firstDateChoice.setUseTextField(true); firstDateChoice.setPickerIconSrc(...........); firstDateChoice.setPickerIconWidth(26); firstDateChoice.setPickerIconHeight(26);
Code:DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() { public String format(Date date) { if (date == null) { return null; } //you'll probably want to create the DateTimeFormat outside this method. //here for illustration purposes DateTimeFormat dateFormatter = DateTimeFormat.getFormat("MM/DD/YY"); String format = dateFormatter.format(date); return format; } }); firstDateChoice = new DateItem(); firstDateChoice.setUseTextField(true); firstDateChoice.setPickerIconSrc(...........); firstDateChoice.setPickerIconWidth(26); firstDateChoice.setPickerIconHeight(26);
who can help?
-
hi zbc,
guess i found kind of a solution:
Here is the code:
Code:DateUtil.setNormalDateDisplayFormatter(new DateDisplayFormatter() { @Override public String format(Date date) { if (date == null) { return null; } final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("dd.MM.yyyy | HH:mm"); String format = dateFormatter.format(date); return format; } }); DateItem dateItem = new DateItem(); dateItem.setUseTextField(true); dateItem.setAttribute("dateFormatter", "toNormalDate");
Comment
Comment