问题描述
我正在使用Liferay 7.1我有以下 liferau-ui:input-date
对象,我想预先选择一个日期:
I'm using Liferay 7.1 I have the following liferau-ui:input-date
object and I want to pre-select a date:
<%
final LocalDate today = LocalDate.now(ZoneId.systemDefault());
%>
<liferay-ui:input-date
dayValue="<%= today.getDayOfMonth()%>"
monthValue="<%=today.getMonth().getValue()%>"
yearValue="<%= today.getYear()%>"
</liferay-ui:input-date>
当我今天输出
的值时在JSP上我得到今天的正确日期: 3 12 2018
。
When I output today
's values directly on the JSP I get the correct date for today: 3 12 2018
.
当元素被渲染时,它选择了错误的日期: 01/03/2019
。 ,我认为可以提供帮助。
When the element is rendered, it has selected the wrong date: 01/03/2019
. There is nothing further documented in the taglibdocs that I think could help.
我该如何解决这个问题?
How can I fix this?
推荐答案
问题是月份值。在Java中,它是1-12,其中有liferay datepicker,它是0-11。
为了显示正确的月份,我从月份值中减去1。这不是一个优雅的解决方案,但我找不到更好的方法。
The problem is the month value. In Java it's 1-12 with liferay datepicker it's 0-11.In order to display the correct month i subtracted 1 from month value. It's not an elegant solution but i couldn't find any better way.
<liferay-ui:input-date
dayValue="<%= today.getDayOfMonth()%>"
monthValue="<%=today.getMonth().getValue() - 1 %>"
yearValue="<%= today.getYear()%>"
</liferay-ui:input-date>
这将呈现12/03/2018
This will render 12/03/2018
这篇关于Liferay日期输入显示错误的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!