JSF标签 h:outputText & f:convertDateTime 解决date正常显示的问题

一、问题:

   用一个<h:outputText/>直接显示日期,显示在页面上的日期会比从数据库里取出的日期提前一天。

二、解决方法:
  
  在<h:outputText/>标签中加入<f:convertDateTime>标签,就可以解决这个问题,代码如下:


<h:outputText value="#{data.t_Date}"> 
        <f:convertDateTime pattern="yyyy年MM月dd日" timeZone="GMT+8"/> 
</h:outputText>
三、问题原因:

   能够解决上面问题的关键是timeZone="GMT+8",也就是说问题处在时区上,timeZone属性规定了时区,所以时间可以正常显示。

四、附录-GMT的介绍

    GMT 就是格林威治标准时间的英文缩写(Greenwich Mean Time 格林尼治标准时间).

    格林威治是伦敦泰晤士河南岸的一个地方,由于从19世纪开始,因为世界各国来往频繁,而欧洲大陆、美洲大陆和亚洲大陆都有各自的时区,所以为免混乱,各国的代表就在1884 年在美国华盛顿召开了国际大会,通过协议选出伦敦的格林威治,作为全球时间的中心点,格林威治标准时间因而诞生。所以有GMT功能的腕表就是说腕表拥有其中的小时表盘可以显示GMT时间。
    GMT+8 就是说与GMT时差8个小时,刚好就是我们中国的时间. 北京时间是 GMT+8.


本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/EvaTian/archive/2008/12/23/3588598.aspx

&lt;p:dataTable id=&quot;nonStdPart_dt&quot; widgetVar=&quot;nonStdPart_dt&quot; value=&quot;#{nonStdPartBean.nonStdParts}&quot; var=&quot;item&quot; paginator=&quot;true&quot; paginatorPosition=&quot;bottom&quot; rows=&quot;20&quot; rowsPerPageTemplate=&quot;10,20,30,40,50&quot; currentPageReportTemplate=&quot;(总记录: {totalRecords}, 页: {currentPage}/{totalPages})&quot; paginatorTemplate=&quot;{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}&quot; emptyMessage=&quot;没有数据&quot; resizableColumns=&quot;true&quot; rowHover=&quot;true&quot; rowIndexVar=&quot;rowvar&quot; lazy=&quot;true&quot; &gt; &lt;p:column headerText=&quot;操作&quot; style=&quot;width:#{nonStdPartBean.isRelatedRole(&#39;工程部角色&#39;,&#39;工程管理角色&#39;) ? &#39;150px;&#39;: nonStdPartBean.isRelatedRole(&#39;接单&#39;)? &#39;100px;&#39; : &#39;50px;&#39;}&quot; rendered=&quot;#{nonStdPartBean.isRelatedRole(&#39;工程部角色&#39;,&#39;工程管理角色&#39;,&#39;接单&#39;,&#39;零件计划角色&#39;)}&quot; &gt; &lt;p:outputPanel style=&quot;width:fit-content;display:flex;justify-content: center;gap:10px;padding: 0 5px;&quot;&gt; &lt;!-- 零件工程 --&gt; &lt;p:commandLink value=&quot;上传图档&quot; actionListener=&quot;#{nonStdPartBean.stagingKey4Down(item)}&quot; disabled=&quot;#{not empty item.getMore(&#39;engUploadOperator&#39;)}&quot; rendered=&quot;#{nonStdPartBean.isRelatedRole(&#39;工程部角色&#39;,&#39;工程管理角色&#39;) and item.state eq NonStdPartState.待工程跟进}&quot; /&gt; &lt;p:commandLink value=&quot;公差待预&quot; actionListener=&quot;#{nonStdPartBean.stagingKey4Tolerance(item)}&quot; update=&quot;@(.toleranceDialogSc)&quot; rendered=&quot;#{nonStdPartBean.isRelatedRole(&#39;工程部角色&#39;,&#39;工程管理角色&#39;) and item.state eq NonStdPartState.待工程跟进}&quot; /&gt; &lt;p:commandLink value=&quot;完成&quot; actionListener=&quot;#{nonStdPartBean.changeState(item)}&quot; rendered=&quot;#{nonStdPartBean.isRelatedRole(&#39;工程部角色&#39;,&#39;工程管理角色&#39;) and item.state eq NonStdPartState.待工程跟进}&quot; /&gt; &lt;!-- 接单 --&gt; &lt;p:commandLink value=&quot;下载图档&quot; ajax=&quot;false&quot; onclick=&quot;PrimeFaces.monitorDownload(start, stop);&quot; update=&quot;&quot; style=&quot;margin-right: 5px;&quot; disabled=&quot;#{empty item.getMore(&#39;engUploadOperator&#39;)}&quot; rendered=&quot;#{nonStdPartBean.isRelatedRole(&#39;接单&#39;) and item.state eq NonStdPartState.待接单跟进}&quot; &gt; &lt;p:fileDownload value=&quot;#{nonStdPartBean.getDownImgFile(item.boardKey)}&quot; /&gt; &lt;/p:commandLink&gt; &lt;!-- 接单, 零件计划 --&gt; &lt;p:commandLink id=&quot;doneCL&quot; value=&quot;完成&quot; actionListener=&quot;#{nonStdPartBean.removeBoard(item.boardKey)}&quot; rendered=&quot;#{(nonStdPartBean.isRelatedRole(&#39;接单&#39;) and item.state eq NonStdPartState.待接单跟进) or (nonStdPartBean.isRelatedRole(&#39;零件计划角色&#39;) and item.state eq NonStdPartState.待计划跟进)}&quot; /&gt; &lt;/p:outputPanel&gt; &lt;/p:column&gt; &lt;p:column headerText=&quot;单号&quot; style=&quot;text-align:center; width: 110px; &quot;&gt; &lt;h:outputText value=&quot;#{item.orderNo}&quot;/&gt; &lt;/p:column&gt; &lt;p:column headerText=&quot;零件编号&quot; style=&quot;text-align:left; width: 130px;&quot;&gt; &lt;h:outputText value=&quot;#{item.partCode}&quot;/&gt; &lt;/p:column&gt; &lt;p:column headerText=&quot;零件说明&quot; style=&quot;text-align:start; width:130px;&quot;&gt; &lt;h:outputText value=&quot;#{item.partDesc}&quot;/&gt; &lt;/p:column&gt; &lt;p:column headerText=&quot;备注&quot; style=&quot;text-align:start; min-width: 250px&quot;&gt; &lt;h:outputText id=&quot;remarkText&quot; value=&quot;#{nonStdPartBean.concatMemoAndToleranceText(item)}&quot;/&gt; &lt;p:tooltip id=&quot;toleranceTextTooltip&quot; for=&quot;remarkText&quot; value=&quot;#{nonStdPartBean.concatMemoAndToleranceText(item)}&quot; position=&quot;top&quot; /&gt; &lt;/p:column&gt; &lt;p:column headerText=&quot;数量&quot; style=&quot;text-align:center; width: 50px;&quot;&gt; &lt;h:outputText value=&quot;#{item.qty}&quot;/&gt; &lt;/p:column&gt; &lt;p:column headerText=&quot;来源类型&quot; style=&quot;text-align:center; width: 70px;&quot;&gt; &lt;h:outputText value=&quot;#{item.sourceType}&quot;/&gt; &lt;/p:column&gt; &lt;p:column headerText=&quot;状态&quot; style=&quot;text-align:center; width: 90px;&quot;&gt; &lt;h:outputText value=&quot;#{item.state}&quot;/&gt; &lt;/p:column&gt; &lt;p:column headerText=&quot;下单日期&quot; style=&quot;text-align:center; width:100px;&quot; sortBy=&quot;#{sort1}&quot;&gt; &lt;h:outputText value=&quot;#{item.bookDate}&quot;&gt; &lt;f:convertDateTime pattern=&quot;dd/MM HH:mm&quot; timeZone=&quot;GMT+8&quot;/&gt; &lt;/h:outputText&gt; &lt;/p:column&gt; &lt;p:column headerText=&quot;工程完成日期&quot; style=&quot;text-align:center; width:100px;&quot;&gt; &lt;h:outputText value=&quot;#{nonStdPartBean.parseDate(item.getMore(&#39;engDoneDate&#39;))}&quot;&gt; &lt;f:convertDateTime pattern=&quot;dd/MM HH:mm&quot; timeZone=&quot;GMT+8&quot;/&gt; &lt;/h:outputText&gt; &lt;/p:column&gt; &lt;p:column headerText=&quot;创建日期&quot; style=&quot;text-align:center; width:100px;&quot;&gt; &lt;h:outputText value=&quot;#{item.creationDate}&quot;&gt; &lt;f:convertDateTime pattern=&quot;dd/MM HH:mm&quot; timeZone=&quot;GMT+8&quot;/&gt; &lt;/h:outputText&gt; &lt;/p:column&gt; &lt;/p:dataTable&gt; 备注栏看不到是什么原因
最新发布
07-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值