nightingale2k1
nightingale2k1

Reputation: 10335

display date / save date in Grails

Is there any way to save / view date in our prefered format ? like dd/MM/yyyy instead of using simple date format everytime I save the date fields ?

for example: I would like to have

class User {
 Date birthDay ; 
}

the user will save the birthDay as '31/12/1988' for example and I would like to display it as that ... without format("dd/MM/yyyy") everytime I found the date (or converting string to date) for saving / updating)

Upvotes: 0

Views: 1642

Answers (3)

Victor Sergienko
Victor Sergienko

Reputation: 13495

If you're talking about date display, you'd better register an own PropertyEditor - with it, will use PropertyEditor's formatting.

If it's about saving to database, you'll need to set up a [custom Hibernate type mapping][2].

[2]: http://grails.org/doc/1.0.x/guide/5. Object Relational Mapping (GORM).html#5.5.2.10%20Custom%20Hibernate%20Types

Upvotes: 0

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

look also at the first answer on Grails Date unmarshalling

Upvotes: 2

amra
amra

Reputation: 16935

You can use metaClass to display the date in wanted format.

Date.metaClass.toString = {
  -> format('dd/MM/yyyy')
}

Upvotes: 3

Related Questions