1.格式化貨幣
世界上許多國家都有不同的貨幣格式和數字格式慣例。針對特定的本地化環境正確地格式化和顯示貨幣是本地化的一個重要部分。
<%@ page pageencoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>currency formatting</title>
</head>
<body>
<h1>currency formatting and locales</h1>
<h3>english, great britain</h3>
<fmt:setlocale value="en_gb" />
<fmt:formatnumber type="currency" value="80000" /><br/>
<h3>english, usa</h3>
<fmt:setlocale value="en_us" />
<fmt:formatnumber type="currency" value="80000" /><br/>
<h3>french, france</h3>
<fmt:setlocale value="fr_fr" />
<fmt:formatnumber type="currency" value="80000" /><br/>
<h3>japanese, japan</h3>
<fmt:setlocale value="ja_jp" />
<fmt:formatnumber type="currency" value="80000" /><br/>
<h3>korean, korea</h3>
<fmt:setlocale value="ko_kr" />
<fmt:formatnumber type="currency" value="80000" /><br/>
<h3>spanish, spain</h3>
<fmt:setlocale value="es_es" />
<fmt:formatnumber type="currency" value="80000" /><br/>
<h3>arabic, egypt</h3>
<fmt:setlocale value="ar_eg" />
<fmt:formatnumber type="currency" value="80000" /><br/>
<h3>using local numeric formatting for different currency</h3>
<h4>english, great britan</h4>
<fmt:setlocale value="en_gb" />
<fmt:formatnumber type="currency" value="80000" /><br/>
<fmt:formatnumber type="currency" value="80000" currencycode="eur"/><br/>
</body>
</html>
2.格式化日期
類似于數字和貨幣格式化,本地化環境還會影響生成日期和時間的方式。
<%@ page pageencoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>date formatting</title>
</head>
<body>
<h1>date formatting and locale</h1>
<fmt:timezone value="est">
<jsp:usebean id="currenttime" class="java.util.date"/>
<h3>english, great britain</h3>
<fmt:setlocale value="en_gb" />
<fmt:formatdate type="both" datestyle="full" timestyle="full" value="${currenttime}" /><br/>
<h3>english, usa</h3>
<fmt:setlocale value="en_us" />
<fmt:formatdate type="both" datestyle="full" timestyle="full" value="${currenttime}" /><br/>
<h3>french, france</h3>
<fmt:setlocale value="fr_fr" />
<fmt:formatdate type="both" datestyle="full" timestyle="full" value="${currenttime}" /><br/>
<h3>japanese, japan</h3>
<fmt:setlocale value="ja_jp" />
<fmt:formatdate type="both" datestyle="full" timestyle="full" value="${currenttime}" /><br/>
<h3>korean, korea</h3>
<fmt:setlocale value="ko_kr" />
<fmt:formatdate type="both" datestyle="full" timestyle="full" value="${currenttime}" /><br/>
<h3>spanish, spain</h3>
<fmt:setlocale value="es_es" />
<fmt:formatdate type="both" datestyle="full" timestyle="full" value="${currenttime}" /><br/>
<h3>arabic, egypt</h3>
<fmt:setlocale value="ar_eg" />
<fmt:formatdate type="both" datestyle="full" timestyle="full" value="${currenttime}" /><br/>
</fmt:timezone>
</body>
</html>
<fmt:formatdate>動作的屬性
type: 可以是time,date或both??刂剖欠裰簧蓵r間,只生成日期,或者時間日期都生成。
datestyle: 可以是short, medium, long 或 full(default)??刂拼蛴∪掌谑褂玫木唧w格式。
timestyle: 可以是short, medium, long 或 full(default)。控制打印時間使用的具體格式。
value: 這是一個java.util.date 類型的值,用于生成日期和時間。
新聞熱點
疑難解答