• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

servlet/jsp 搞代码 7年前 (2018-06-18) 221次浏览 已收录 0个评论

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>

http://www.gaodaima.com/?p=43327JSP 国际化-格式化货币和日期

</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&#8221; %>
<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 类型的值,用于生成日期和时间。

欢迎大家阅读《JSP 国际化-格式化货币和日期》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:JSP 国际化-格式化货币和日期

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址