1. Format Currency
Many countries around the world have different currency formats and number formatting conventions. Formatting and displaying currency correctly for a specific localization environment is an important part of localization.
<%@ 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. Formatting dates
is similar to number and currency formatting, and the localization environment also affects the way dates and times are generated.
<%@ 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>The action attribute
type: can be time, date or both. Controls whether only time, only date, or both time and date are generated.
dateStyle: can be short, medium, long or full (default). Controls the specific format used for printed dates.
timeStyle: can be short, medium, long or full (default). Controls the specific format used for printing times.
value: This is a value of type java.util.Date used to generate date and time.