How to change date format in Calendar Widget of SmartGWT?
Default calendar widget of Smartgwt Component shows date as Sun 10/31 ( MM/DD format ) .
http://www.smart开发者_开发问答client.com/smartgwt/showcase/#simple_calendar_category
How can I change the date format to DD/MM formatin Calendar Widget ?
Thanks in advance for having a look, Sachin
SmartGwt provides a static DateUtil for changing date formats.Put the following code somewhere in your application and it will change the date format through out the application
DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
public String format(Date date) {
if(date == null) return null;
final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("DD/MM/yyyy");
String format = dateFormatter.format(date);
return format;
}
});
Take a look to the com.smartgwt.client.util.DateUtil
specifically to the methods setShortDateDisplayFormat
and setShortDateDisplayFormatter
This should solve your problem, according to the documentation.
put
this.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATE);
in constructor
@aruns is correct, however another step is need if you are using RelativeDateItem
DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter()
{
public String format(Date date)
{
if(date == null)
{
return null;
}
else
{
final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
return dateFormatter.format(date);
}
}
});
DateUtil.setDateParser(new DateParser()
{
public Date parse(String dateString)
{
final DateTimeFormat format = DateTimeFormat.getFormat(DATE_FORMAT);
return format.parse(dateString);
}
});
The DateFormat is defined in the GWT documentation
精彩评论