jstl之fmt

<%@ page language="java" contentType="text/html; charset=UTF-8"
	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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>fmt:formatDate</title>
</head>
<body>
	<h3>Number Format:</h3>
	<c:set var="now" value="<%=new java.util.Date()%>" />

	<p>
		Formatted Date (1):
		<fmt:formatDate type="time" value="${now}" />
	</p>
	<p>
		Formatted Date (2):
		<fmt:formatDate type="date" value="${now}" />
	</p>
	<p>
		Formatted Date (3):
		<fmt:formatDate type="both" value="${now}" />
	</p>
	<p>
		Formatted Date (4):
		<fmt:formatDate type="both" dateStyle="short" timeStyle="short"
			value="${now}" />
	</p>
	<p>
		Formatted Date (5):
		<fmt:formatDate type="both" dateStyle="medium" timeStyle="medium"
			value="${now}" />
	</p>
	<p>
		Formatted Date (6):
		<fmt:formatDate type="both" dateStyle="long" timeStyle="long"
			value="${now}" />
	</p>
	<p>
		Formatted Date (7):
		<fmt:formatDate pattern="yyyy-MM-dd" value="${now}" />
	</p>

</body>
</html>


<%@ page language="java" contentType="text/html; charset=UTF-8"
	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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>fmt:formatNumber</title>
</head>
<body>
	<h3>Number Format:</h3>
	<c:set var="balance" value="120000.2309" />
	<c:out value="${balance }"></c:out>
	<p>
		Formatted Number (1):
		<fmt:formatNumber value="${balance}" type="currency" />
	</p>
	<p>
		Formatted Number (2):
		<fmt:formatNumber type="number" maxIntegerDigits="3"
			value="${balance}" />
	</p>
	<p>
		Formatted Number (3):
		<fmt:formatNumber type="number" maxFractionDigits="3"
			value="${balance}" />
	</p>
	<p>
		Formatted Number (4):
		<fmt:formatNumber type="number" groupingUsed="false"
			value="${balance}" />
	</p>
	<p>
		Formatted Number (5):
		<fmt:formatNumber type="percent" maxIntegerDigits="3"
			value="${balance}" />
	</p>
	<p>
		Formatted Number (6):
		<fmt:formatNumber type="percent" minFractionDigits="10"
			value="${balance}" />
	</p>
	<p>
		Formatted Number (7):
		<fmt:formatNumber type="percent" maxIntegerDigits="3"
			value="${balance}" />
	</p>
	<p>
		Formatted Number (8):
		<fmt:formatNumber type="number" pattern="###.###E0" value="${balance}" />
	</p>
	<p>
		Currency in USA :
		<fmt:setLocale value="en_US" />
		<fmt:formatNumber value="${balance}" type="currency" />
	</p>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
	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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>fmt:parseDate</title>
</head>
<body>
	<h3>Date Parsing:</h3>
	<c:set var="now" value="20-10-2010" />

	<fmt:parseDate value="${now}" var="parsedEmpDate" pattern="dd-MM-yyyy" />
	<p>
		Parsed Date:
		<c:out value="${parsedEmpDate}" />
	</p>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
	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"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>fmt:parseNumber</title>
</head>
<body>
	<h3>Number Parsing:</h3>
	<c:set var="balance" value="1250003.350" />

	<fmt:parseNumber var="i" type="number" value="${balance}" />
	<p>
		Parsed Number (1) :
		<c:out value="${i}" />
	</p>
	<fmt:parseNumber var="i" integerOnly="true" type="number"
		value="${balance}" />
	<p>
		Parsed Number (2) :
		<c:out value="${i}" />
	</p>
</body>
</html>


你可能感兴趣的:(jstl之fmt)