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
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}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With