Showing the Date in correct format in a Smartgwt project

1k Views Asked by At

I am getting a date from JSON in the following format 22 07 2014 12:04:12. This is the code I have written:

field.setCellFormatter(new CellFormatter() {
    @Override
    public String format(Object arg0, ListGridRecord arg1, int arg2, int arg3) {
        final DateTimeFormat fmt = DateTimeFormat.getFormat("dd MM yyyy hh:mm");
        final Date date = (Date) arg0;

            arg1.setAttribute(name, date);
            return fmt.format(date);
});

where field is the Date field in ListGrid. But this displays a blank field in the ListGrid. I can't figure out a way to show it in the following format: 22 Jul 2014 00:04

1

There are 1 best solutions below

0
On

According to the documentation, the server must send dates with the following format:

dateField: "2007-04-22"

timeField: "11:07:13"

dateTimeField: "2007-04-22T11:07:13"

dateTimeField: "2007-04-22T11:07:13.582"

You can achieve that with this snippet:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
sdf.format(myDate);

Then, in the client side, you can format the date with SmartGWT:

myListGridField.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATETIME);