【问题标题】:How to display only date "dd/MM/yyy" in primefaces calendar incide of <p:inplace/>如何在 <p:inplace/> 内的 primefaces 日历中仅显示日期“dd/MM/yyyy”
【发布时间】:2014-08-21 12:36:59
【问题描述】:

我试图在此代码中仅显示日期、月份和年份,但是当我输入初始日期并在原地单击保存按钮时,显示日期如下:“Thu Aug 21 00:00:00 BOT 2014" 我只想这样显示:“21/08/2014”或“21/Aug/2014”

这是代码:

<p:outputLabel value="#{msg['startDate']}" for="inputInitialDate"/>
<p:inplace id="inputInitialDate" editor="true" emptyLabel="#{msg['period.addInitialDate']}" 
                               disabled="#{periodManager.currentPeriod.state == 'DUE'}">
    <p:ajax event="save" listener="#{periodManager.addDateToPeriod}" update="formContainer"/>
    <p:calendar value="#{periodManager.currentPeriod.initialDate}" pattern="dd/MM/yyyy"
                                    widgetVar="calendarInputWidget"/>
</p:inplace>
<p:message for="inputInitialDate"/>

【问题讨论】:

    标签: ajax jsf primefaces calendar


    【解决方案1】:

    &lt;f:convertDateTime&gt; 添加到日历中,重复pattern&lt;p:calendar&gt; 自己的pattern 属性确实是最常被误解的。它仅适用于应在日历选择弹出窗口中显示的模式,而不适用于输出的模式。

    <p:calendar ... pattern="dd/MM/yyyy">
        <f:convertDateTime pattern="dd/MM/yyyy" />
    </p:calendar>
    

    或者,再干一点。

    <p:calendar ... pattern="dd/MM/yyyy">
        <f:convertDateTime pattern="#{component.pattern}" />
    </p:calendar>
    

    【讨论】:

    • 谢谢,现在可以了。为了显示月份文字,我应该如何使用该模式?
    • 这些模式基于SimpleDateFormat 规则,在其javadoc 中有非常清楚的概述。使用 MMM 表示 3 个字符的月份缩写,使用 MMMM 表示完整的月份名称。对于与当前问题无关的新问题,请按右上角的[]按钮。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 1970-01-01
    • 2018-03-31
    • 2012-09-16
    • 2021-07-09
    相关资源
    最近更新 更多