andré_resende
andré_resende

Reputation: 155

Grails date type

In my view I have something like this:

Date: ${it.date}

which has the following output:

Date: 2011-05-24 00:00:00.0.

How can I change the Date formation so that the last part(00:00:00.0) does not appear?

Upvotes: 1

Views: 1086

Answers (2)

loeschg
loeschg

Reputation: 30581

If you're doing a lot of date manipulations, I'd highly suggest getting the JodaTime plugin http://www.grails.org/plugin/joda-time. It has its own tag library, and formatting the DateTime can be simply done using the toString() method.

    DateTime dt = new DateTime()
    println (dt.toString("YYYY-MM-dd"))

In your case you could do the following (if using JodaTime):

    Date: ${it.toString("yyyy-MM-dd")}

Upvotes: 0

lucke84
lucke84

Reputation: 4636

Yes, you can format a date with the related tag, which is , like this:

<g:formatDate format="yyyy-MM-dd" date="${it.date}"/>

Here more info: http://www.grails.org/GSP+Tag+-+formatDate Hope this helps. :)

Upvotes: 1

Related Questions