开发者

JSTL padding int with leading zeros

开发者 https://www.devze.com 2023-03-22 06:04 出处:网络
I\'m trying to use JSTL to build a form.I have a select input for the months but I need the months to always be two digits i.e. padded left with a Zero for 1-9.

I'm trying to use JSTL to build a form. I have a select input for the months but I need the months to always be two digits i.e. padded left with a Zero for 1-9.

I have this but obvious it doesn't give me what I want.

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <select class="formInput">
        <c:forEach var="开发者_StackOverflow社区i" begin="1" end="12" step="1" varStatus ="status">
            <option><fmt:formatNumber pattern="##" value="${i}" /></option>
        </c:forEach>
    </select>

This has to have been done before but I can't find an example after a bit of searching.


found the answer: minIntegerDigits

<select class="formInput">
    <c:forEach var="i" begin="1" end="12" step="1" varStatus ="status">
        <option><fmt:formatNumber minIntegerDigits="2" value="${i}" /></option>
    </c:forEach>
</select>
0

精彩评论

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