본문 바로가기
JSP/JSP기초

[Javascript]다국어처리 국제화

by 미눅스[멘토] 2023. 7. 7.
728x90

현재 로케일의 국가, 날씨, 통화

<%@page import="java.text.NumberFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Locale"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Internationalization</title>
</head>
<body>
	<h3>현재 로케일의 국가, 날씨, 통화</h3>
	<%
		Locale locale = request.getLocale();
		Date currentDate =  new Date();
		DateFormat dateFormat = DateFormat.getDateInstance(
				DateFormat.FULL, locale);
		NumberFormat numberFormat = 
				NumberFormat.getNumberInstance(locale);
		
	%>
	<p>국가 : <%=locale.getDisplayCountry() %></p>
	<p>날짜 : <%=dateFormat.format(currentDate) %></p>
	<p>숫자 : <%=numberFormat.format(12345.67) %> </p>
</body>
</html>

결과

 

 


국제화

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"  %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
	<h2>국제화</h2>
	<!-- 숫자 : 3,200,100 -->
	<p>숫자 : <fmt:formatNumber value="3200100" /> </p>
	<!--  3,200,100 -->
	<p>숫자 : <fmt:formatNumber value="3200100" type="number" /> </p>
	<!--  3200100 -->
	<p>숫자 : <fmt:formatNumber value="3200100" type="number" 
			groupingUsed="false"/> </p>
	<!--  \3200100 -->
	<p>숫자 : <fmt:formatNumber value="3200100" type="number" 
			groupingUsed="true"/> </p>
	<!--  금3,200,100 -->
	<p>숫자 : <fmt:formatNumber value="3200100" type="number" 
			currencySymbol="금"/> </p>
	<!--  45% -->
	<p>숫자 : <fmt:formatNumber value="0.45" type="percent" /> </p>
	<!--  3200100.450 -->
	<p>숫자 : <fmt:formatNumber value="3200100.45" pattern=".000" /> </p>
	<!--  가장 많이 사용!!! 천단위 구분기호. 소수점 2자리 3,200,100.46 -->
	<p>숫자 : <fmt:formatNumber value="3200100.456" pattern="#,#00.00#" /> </p>
</body>
</html>

결과

 

 

 

 


국제화

<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"  %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
	<h2>국제화</h2>
	<!-- 2023.07.07 -->
	<p><fmt:formatDate value="<%=new Date() %>" type="date" /></p>
	<!-- 오전 9:38:44 -->
	<p><fmt:formatDate value="<%=new Date() %>" type="time" /></p>
	<!-- 2023.07.07 오전 9:38:44 -->
	<p><fmt:formatDate value="<%=new Date() %>" type="both" 
		dateStyle="default" timeStyle="default"/></p>
	<p><fmt:formatDate value="<%=new Date() %>" type="both" 
		dateStyle="short" timeStyle="short"/></p>
	<p><fmt:formatDate value="<%=new Date() %>" type="both" 
		dateStyle="medium" timeStyle="medium"/></p>
	<p><fmt:formatDate value="<%=new Date() %>" type="both" 
		dateStyle="long" timeStyle="long"/></p>
	<p><fmt:formatDate value="<%=new Date() %>" type="both" 
		dateStyle="full" timeStyle="full"/></p>
		
		
	<!-- 가장 많이 사용됨!
	oracle Date자료형
	 -->
	<p><fmt:formatDate value="<%=new Date() %>" pattern="yyyy-MM-dd"/></p>
	<p><fmt:formatDate value="<%=new Date() %>" pattern="yyyy-MM-dd hh:mm:ss"/></p>
	
</body>
</html>

결과


 

 

 

JSTL fmt 태그

- 다국어 문서 처리르 위한 국제화 및 지역화 태그

- JSTL fmt 태그의 종류