且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Grails中更改joda-time默认的DateTime格式

更新时间:2023-02-18 23:10:49

在config.groovy中定义这个

  jodatime {form at.org.joda.time.DateTime =dd MMM YYYY HH:mm a} 

和应该照顾它。

I am using Grails 2.0.3 (groovy 1.8.6) with joda-time:1.3.1 and joda-time-templates plugins. Everything works perfectly but I would like to change displayed format for date and time. How can I do that? Every domain is scaffolded so I do not have access to any view to render it manually.

My domain

import org.joda.time.*
import org.joda.time.contrib.hibernate.*

    class Game {

        Team host
        Team guest
        String location
        DateTime date


        static mapping = {
            date type: PersistentDateTimeTZ, {
                column name: "date_timestamp"
                column name: "date_zone"
            }
        }
    }

rendered date

Date 5/24/12 5:53 PM

I would like to get it as

Date 5 may 2012 17:53 PM 

Is there any way to translate name of month

define this in config.groovy

jodatime {  format.org.joda.time.DateTime = "dd MMM YYYY HH:mm a" }

and that should take care of it.