我使用了丰富的 ui 的日期选择器。我得到正确的日期值。但是如果我想设置richui的datechooser的值是怎么做的呢?
问问题
3261 次
1 回答
1
You'll have to parse the date manually in your controller because your format/pattern is unknown to grails.
def date = Date().parse("MM-dd-yyyy", params.date); //<-- consider using a constant for the date format
or reset the params value to the java.util.Date class.
params.date = Date().parse("MM-dd-yyyy", params.date); //<-- re-assigns date string as date class
You might also want test the inbound format to make sure someone doesn't manually enter an invalid format...
def date = (parmas.date.matches("\\d{2}-\\d{2}-\\d{4}"))? Date().parse("MM-dd-yyyy", params.date) : null; //<-- safely return null if doesn't match a date regex.
see also:
于 2012-04-24T12:03:20.973 回答