在Grails中将“date.struct”更改为date

在Grails中将“date.struct”更改为date,grails,Grails,在我看来,在Grails2.5.1应用程序中,控制器中该字段的返回值是date.struct,我如何将该值更改为实际日期。 以下是我的看法: <div class="fieldcontain ${hasErrors(bean: empRefInstance, field: 'endDate', 'error')} "> <label for="endDate"> <g:message code="empRef.endDate.label" default="

在我看来,在Grails2.5.1应用程序中,控制器中该字段的返回值是date.struct,我如何将该值更改为实际日期。 以下是我的看法:

<div class="fieldcontain ${hasErrors(bean: empRefInstance, field: 'endDate', 'error')} ">
<label for="endDate">
    <g:message code="empRef.endDate.label" default="End Date" />

</label>
<g:datePicker name="endDate" relativeYears="[-90..0]" precision="day"  value="${empRefInstance?.endDate}" default="none" noSelection="['null':'Present']" />

现在发生的是,从的日期实际上已断开为单独的参数键。例如,您将拥有诸如params.endDate_month、params.endDate_day、params.endDate_year等键。所以你可以把它拼凑成这样一个日期:

def endDate = new Calendar().with {
    set(params.endDate_year, params.endDate_month, params.endDate_day, params.endDate_hour, params.endDate_minute, 0)
    getTime() // Returns a Date instance.
}

您可以使用date.struct构建一个字符串,然后像中一样使用SimpleDataFormat


我以前从未见过这种情况。你如何使用g:datePicker?请在问题中添加实际代码。并在controller方法中添加访问它的方式。@EmmanuelRosa,我编辑了该问题的原始postany想法?
def endDate = new Calendar().with {
    set(params.endDate_year, params.endDate_month, params.endDate_day, params.endDate_hour, params.endDate_minute, 0)
    getTime() // Returns a Date instance.
}
    String Date = endDate_year+"/"+endDate_month+"/"+endDate_day
    SimpleDateFormat sdformat = new SimpleDateFormat("yyyy/MM/dd");
    Date dt = sdformat.parse(date);
    println(dt)