Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails change Date format in gsp view

When I try to use date format tag in gsp view to change the format of my date but it doesn't work.

This is my code:

class MyDate {  
    Date date
}

MyDateController:

....
def unixSeconds = params["date"].replaceAll("\"", "") as long  //params["date"]="1386157660"
Date date = new Date(unixSeconds*1000L)
myDateInstance = new MyDate(date:date)
....

gsp View:

${myDateInstance.date.format('yyyy-MM-dd HH:mm')}

The format that I have is 2013-12-04 12:47:40.0 instead of 2013-12-04 12:47

like image 870
Jils Avatar asked Dec 04 '13 13:12

Jils


1 Answers

Afaict, that shouldn't happen and I can't see how it is happening...

Are you sure that's the line of code that's generating the output you're seeing?

You could try the Grails formatDate tag in its place:

<g:formatDate format="yyyy-MM-dd HH:mm" date="${myDateInstance.date}"/>
like image 111
tim_yates Avatar answered Sep 28 '22 02:09

tim_yates