首页 > 开发 > JSP > 正文

JSP 国际化-格式化货币和日期

2020-02-05 13:49:37
字体:
来源:转载
供稿:网友
国内最大的酷站演示中心!

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。控制是否只生成时间,只生成日期,或者时间日期都生成。
datestyle: 可以是short, medium, long 或 full(default)。控制打印日期使用的具体格式。
timestyle: 可以是short, medium, long 或 full(default)。控制打印时间使用的具体格式。
value: 这是一个java.util.date 类型的值,用于生成日期和时间。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表