首先引入格式化库<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<h1>测试格式化库</h1>
<li>格式化日期</li><br>
today(default):<fmt:formatDate value="${today}"/><br>
today(type="date"):<fmt:formatDate value="${today}" type="date"/><br>
today(type="time"):<fmt:formatDate value="${today}" type="time"/><br>
today(type="both"):<fmt:formatDate value="${today}" type="both"/><br>
today(dateStyle="short"):<fmt:formatDate value="${today}" dateStyle="short"/><br>
today(dateStyle="medium"):<fmt:formatDate value="${today}" dateStyle="medium"/><br>
today(dateStyle="long"):<fmt:formatDate value="${today}" dateStyle="long"/><br>
today(dateStyle="full"):<fmt:formatDate value="${today}" dateStyle="full"/><br>
today(pattern="yyyy/MM/dd HH:mm:ss"):<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss" var="d"/><br>
${d }<br>
<p>
<li>格式化数字</li><br>
n(default):<fmt:formatNumber value="${n}"/><br>
n(pattern="###,###.####"):<fmt:formatNumber value="${n}" pattern="###,###.####"/><br>
n(pattern="###,###.0000"):<fmt:formatNumber value="${n}" pattern="###,###.0000"/><br>
n(groupingUsed="false"):<fmt:formatNumber value="${n}" groupingUsed="false"/><br>
n(maxIntegerDigits="10" minIntegerDigits="9"):<fmt:formatNumber value="${n}" maxIntegerDigits="10" minIntegerDigits="9"/><br>
n(maxFractionDigits="8" minFractionDigits="4"):<fmt:formatNumber value="${n}" maxFractionDigits="8" minFractionDigits="4"/><br>
n(type="currency"):<fmt:formatNumber value="${n}" type="currency"/><br>
n(type="currency" currencySymbol="$"):<fmt:formatNumber value="${n}" type="currency" currencySymbol="$"/><br>
<h1>测试格式化库</h1>
<li>格式化日期</li><br>
today(default):<fmt:formatDate value="${today}"/><br>
today(type="date"):<fmt:formatDate value="${today}" type="date"/><br>
today(type="time"):<fmt:formatDate value="${today}" type="time"/><br>
today(type="both"):<fmt:formatDate value="${today}" type="both"/><br>
today(dateStyle="short"):<fmt:formatDate value="${today}" dateStyle="short"/><br>
today(dateStyle="medium"):<fmt:formatDate value="${today}" dateStyle="medium"/><br>
today(dateStyle="long"):<fmt:formatDate value="${today}" dateStyle="long"/><br>
today(dateStyle="full"):<fmt:formatDate value="${today}" dateStyle="full"/><br>
today(pattern="yyyy/MM/dd HH:mm:ss"):<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss" var="d"/><br>
${d }<br>
<p>
<li>格式化数字</li><br>
n(default):<fmt:formatNumber value="${n}"/><br>
n(pattern="###,###.####"):<fmt:formatNumber value="${n}" pattern="###,###.####"/><br>
n(pattern="###,###.0000"):<fmt:formatNumber value="${n}" pattern="###,###.0000"/><br>
n(groupingUsed="false"):<fmt:formatNumber value="${n}" groupingUsed="false"/><br>
n(maxIntegerDigits="10" minIntegerDigits="9"):<fmt:formatNumber value="${n}" maxIntegerDigits="10" minIntegerDigits="9"/><br>
n(maxFractionDigits="8" minFractionDigits="4"):<fmt:formatNumber value="${n}" maxFractionDigits="8" minFractionDigits="4"/><br>
n(type="currency"):<fmt:formatNumber value="${n}" type="currency"/><br>
n(type="currency" currencySymbol="$"):<fmt:formatNumber value="${n}" type="currency" currencySymbol="$"/><br>
n(type="percent"):<fmt:formatNumber value="${p}" type="percent" minFractionDigits="2"/><br>
<fmt:formatNumber value="${price*discount}" type="currency" pattern="$.00"/> //-- $12.00
<fmt:formatNumber value="${price*discount}" type="currency" pattern="$.0#"/> //-- $12.0 <fmt:formatNumber value="${price*discount}" type="currency"/> //-- $1,234,567,890.00(那个货币的符号和当前web服务器的 local 设定有关)
<fmt:formatNumber value="123456.7891" pattern="#,#00.0#"/>// -- 123,456.79
<fmt:formatNumber value="123456.7" pattern="#,#00.0#"/> //-- 123,456.7
<fmt:formatNumber value="123456.7" pattern="#,#00.00#"/>// -- 123,456.70
<fmt:formatNumber value="12" type="percent" /> //-- 1,200% (type 可以是currency、 number、 和percent)。