开发者

JSTL formatDate always format the patten "MMM" to "Jan"

开发者 https://www.devze.com 2023-02-13 22:29 出处:网络
I开发者_如何学运维n a foreach loop, I set curMonth and curDisplayedMonth as follows: <fmt:formatDate value=\"${curDate}\" type=\"date\" pattern=\"m\" var=\"curMonth\" />

I开发者_如何学运维n a foreach loop, I set curMonth and curDisplayedMonth as follows:

<fmt:formatDate value="${curDate}" type="date" pattern="m" var="curMonth" />
<fmt:formatDate value="${curDate}" type="date" pattern="MMM" var="curDisplayedMonth" />

and use them in the dropdown list as

<option value="<c:out value="${curMonth}"/>" <c:if test="${selectedMonth == curMonth}">selected</c:if>>
<c:out value="${curDisplayedMonth}"/>
</option>

but it formats all to Jan:


JSTL formatDate always format the patten "MMM" to "Jan"


and the values in the options are correct:


JSTL formatDate always format the patten "MMM" to "Jan"


You need to correct your pattern option. For displaying the month with JSTL formatDate, use the following options:

<%-- Displays numeric month (ex: 1) --%>
<fmt:formatDate value="${curDate}" pattern="M" />

<%-- Displays  two-digit numeric month (ex: 01) --%>
<fmt:formatDate value="${curDate}" pattern="MM" />

<%-- Displays  the month abbreviation (ex: Jan) --%>
<fmt:formatDate value="${curDate}" pattern="MMM" />

<%-- Displays  the full month name (ex: January) --%>
<fmt:formatDate value="${curDate}" pattern="MMMM" />

Also, in your example above:

<fmt:formatDate value="${curDate}" type="date" pattern="m" var="curMonth" />

pattern="m" represents the minute.


The type and pattern attributes are mutually exclusive. You use one or the other, but not both.

The type attribute is just a convenient way to specify certain common patterns.

If you want to use pattern, you should remove the type="date" attributes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号