Liferay date-input displays wrong date

2019-06-09 01:01发布

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>

When I output today's values directly on the JSP I get the correct date for today: 3 12 2018.

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?

1条回答
我想做一个坏孩纸
2楼-- · 2019-06-09 01:37

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>

This will render 12/03/2018

查看更多
登录 后发表回答