Question

I don't know if there is a question like this but I didn't find what I was looking for. This is the problem:

In my database I have a table that has a value (String) of a timestamp. (i.e. 1370842140205)

When I get that value in my <display:table> it shows exactly like that 1370842140205.

What I want is this: 10.6.2013 5.29.00

How can i convert that String into desired date format in my .jsp file?

Thanks.

EDIT:

I tried to use this:

<display:table  name="${row.rows}">
    <display:column property="date" title="DATE" format="{0,date,MM.dd.yyyy HH.mm.ss}"/>
</display:table>

But it didn't work for me.

Was it helpful?

Solution 3

I managed to fix it by my own. I modified the Select query. I used this:

SELECT DATE_FORMAT(FROM_UNIXTIME(`date` / 1000.0 ) ,  '%Y.%m.%d %k.%i.%s' ) as 'date' FROM table

Then I displayed it in my table as this:

<display:table  name="${row.rows}">
    <display:column property="date" title="DATE"/>
</display:table>

OTHER TIPS

Try something like this:

long timeStamp = 1370842140205L;
Date time = new Date(timeStamp*1000);
String yourDate = time.toString();

Try this.

    long time=Long.parseLong("1370842140205");
    Date date = new Date(time);
    SimpleDateFormat sdf=new SimpleDateFormat("dd.MM.yyyy hh.mm.ss");
    System.out.println(sdf.format(date));

Use a column decorator to change your date and time format

    import javax.servlet.jsp.PageContext;
    import org.displaytag.decorator.DisplaytagColumnDecorator;
    import org.displaytag.exception.DecoratorException;
    import org.displaytag.properties.MediaTypeEnum;

    public class DateTimeDisplayColumnDecorator implements
    DisplaytagColumnDecorator {

@Override
public Object decorate(Object arg0, PageContext arg1, MediaTypeEnum arg2)
        throws DecoratorException {
    // Do your date conbersion code here
}

}

And in jsp add the decorator class name in decorator property

<display:column property="date" title="DATE"
 decorator="DateTimeDisplayColumnDecorator"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top