Search code examples
dategrailsgrails-ormgsp

Grails Date variable will not set the time


I make a simple domain class

class Meetings {

    Date when
    String where
}

Then I run 'generate-all' on Meetings. I then start the app 'RunApp'. In the app I'm able to to choose the month, day, and year for the when variable, however I can't choose the time as in hours:minutes (example 7:30). I wouldn't expect to be able to do this, but if I save the date it formats it as month, day, year, and then -00:00:00. How do I set the time using the date variable? or is there another way?


Solution

  • If you are using the datepicker tag in grails, it is pretty straight forward. In the views folder under a domain class folder there is _form.gsp. Inside _form.gsp is a date picker tag.

    <g:datePicker name="dateTimeVariableName" value="${dateTimeValue}"
              default="${new Date().clearTime()}" precision="minute"/>
    

    The keyword here is precision.

    You should check the documentation. Its always a good idea. Hope this helps.