如何将日期选择器日期输入文本字段?

时间:2016-03-19 10:40:39

标签: java sql date datepicker

<package name="artisan" namespace="/artisan" extends="struts-default">
    <interceptors>
    <interceptor-stack name="basicStack">
        <interceptor-ref name="createSession" />
        <interceptor-ref name="defaultStack">  
            <param name="exception.logEnabled">true</param>  
            <param name="exception.logLevel">error</param>  
        </interceptor-ref>  
        <interceptor-ref name="alias" />
        <interceptor-ref name="servletConfig" />
        <interceptor-ref name="prepare" />
        <interceptor-ref name="i18n" />
        <interceptor-ref name="chain" />
        <interceptor-ref name="modelDriven" />
        <interceptor-ref name="checkbox" />
        <interceptor-ref name="params" />
        <interceptor-ref name="conversionError" />
        <interceptor-ref name="validation">
                <param name="excludeMethods">input,back,cancel,browse</param>
                <param name="validateAnnotatedMethodOnly">true</param>
        </interceptor-ref>
        <interceptor-ref name="exception">
            <param name="logEnabled">true</param>
            <param name="logLevel">warn</param>
        </interceptor-ref>
    </interceptor-stack>
</interceptors>
<default-interceptor-ref name="basicStack" />
    <default-action-ref name="notFound" />
<global-results>
    <result name="ERROR">/exception.jsp</result>
    <result name="error">/exception.jsp</result>
    <result name="INPUT">/input_exception.jsp</result>
    <result name="input">/input_exception.jsp</result>
    <result name="INDEX_PAGE">/index.jsp</result>
    <result name="no_priviledge">/no_priviledge.jsp</result>
    <result name="no_login">/no_login.jsp</result>
</global-results>

<action name="artisanDateQueryAction" class="artisanDateQueryAction">
    <result name="query_work_success">/adminsys/artisan/search_artisan_work.jsp</result>
    <result name="artisan_date_list">/adminsys/artisan/date/artisan_date_list.jsp</result>
</action>
</package>

提示:Date Date1 = jXDatePicker1.getDate(); datestartField.setText(Date1); 无法转换为日期。

1 个答案:

答案 0 :(得分:0)

日期无法分配给textfield,因为它是对象。您可以使用SimpledateFormat将其转换为String

    Date Date1 = jXDatePicker1.getDate();
    DateFormat df = new SimpleDateFormat("dd MMM yyyy hh:mm a",
                                Locale.US); 
   datestartField.setText(df.format(date1));

希望这对你有帮助..