丰富的日历日期格式

发布于 2024-12-13 07:44:13 字数 794 浏览 3 评论 0原文

我使用 rich:calendar 和特定模式 datePattern="dd/MM/yyyy"。当我尝试从日历中获取字符串值并使用 SimpleDateFormat ("dd/MM/yyyy") 解析它时,我遇到了一些问题,我发现变量中的日期格式不是我所期望的: Tue Nov 22 00:00:00 EET 2011

以下是一些代码:

丰富:日历

<rich:calendar value="#{validateReportAction.selectedDate}"  
   required="true" 
   requiredMessage="You must select a date" 
   mode="ajax"
   id="date"
   datePattern="dd/MM/yyyy"/>

在豆子

DateFormat formatter;
Date date; 
formatter = new SimpleDateFormat("dd/MM/yyyy");
date = (Date) formatter.parse(getSelectedDate());

,其中 getSelectedDate() 返回 Tue Nov 22 00:00:00 EET 2011 但我只想要日/月/年。我怎样才能做到这一点?

I use rich:calendar with a specific pattern datePattern="dd/MM/yyyy". When I tried to get the string value from the calendar and parse it using SimpleDateFormat ("dd/MM/yyyy") I had some issues and I saw the date format in my variable is not what I expected: Tue Nov 22 00:00:00 EET 2011

Here is some code:

rich:calendar

<rich:calendar value="#{validateReportAction.selectedDate}"  
   required="true" 
   requiredMessage="You must select a date" 
   mode="ajax"
   id="date"
   datePattern="dd/MM/yyyy"/>

in bean

DateFormat formatter;
Date date; 
formatter = new SimpleDateFormat("dd/MM/yyyy");
date = (Date) formatter.parse(getSelectedDate());

where getSelectedDate() returns Tue Nov 22 00:00:00 EET 2011 but I want only the day/month/year. How can I achieve that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

携余温的黄昏 2024-12-20 07:44:13

这是我可以正常工作的代码;

<rich:calendar id="scheduledDateStart" 
            value="#{Scheduled.scheduledDateStart}"
    popup="true" 
            enableManualInput="#{true}"
            scrollMode="client"                             
           timeZone="#{timeZone.timeZone}"
   datePattern="MM,dd,yyyy"                             
 >                   
 <f:convertDateTime type="date" pattern="MMMM dd, yyyy"  timeZone="#{timeZone.timeZone}"/>
</rich:calendar>

Here is the code that i have that works properly;

<rich:calendar id="scheduledDateStart" 
            value="#{Scheduled.scheduledDateStart}"
    popup="true" 
            enableManualInput="#{true}"
            scrollMode="client"                             
           timeZone="#{timeZone.timeZone}"
   datePattern="MM,dd,yyyy"                             
 >                   
 <f:convertDateTime type="date" pattern="MMMM dd, yyyy"  timeZone="#{timeZone.timeZone}"/>
</rich:calendar>
落在眉间の轻吻 2024-12-20 07:44:13

将此属性添加到您的标签中,看看它是否解决了问题:

<f:convertDateTime type="date" pattern="dd/MM/yyyy"  timeZone="#{timeZone.timeZone}"/>

问候!

Add this attribute inside your tag and see if it fixes the issue:

<f:convertDateTime type="date" pattern="dd/MM/yyyy"  timeZone="#{timeZone.timeZone}"/>

Regards!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文