I have seen a few posts related to using the g:datePicker in Grails. Using this it looks like you can just pick the value off the params like so params.myDate.
However, when I try to do something like this in my view:
view:
<g:link controller="c" action="a" params="[fromDate:(new Date())]">
controller:
def dateval = params.fromDate as Date
The date is not parsing out correctly. Is there something else I should be doing in the view to make the date 'parsable' by the controller. I've looked around and haven't found this in any posts where datePicker is not used.
I prefer to send time instead of dates from the client.
<g:link controller="c" action="a" params="[fromDate:(new Date().time)]">
And in action I use the constructor of Date that takes time.
def date = params.date
date = date instanceof Date ? date : new Date(date as Long)
I have created a method in DateUtil class to handle this. This works fine for me.
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