java 丰富的日历日期格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7982528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 22:33:34  来源:igfitidea点击:

rich calendar date formatting

javajsfjsf-2richfaces

提问by nyxz

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

我使用具有特定模式的rich:calendar datePattern="dd/MM/yyyy"。当我尝试从日历中获取字符串值并使用解析它时,SimpleDateFormat ("dd/MM/yyyy")我遇到了一些问题,我看到变量中的日期格式不是我所期望的: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 2011but I want only the day/month/year. How can I achieve that?

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

回答by Mechkov

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>

回答by Mechkov

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!

问候!