标签:
jstl_fmt.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="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=GB18030"> <title>Insert title here</title> </head> <body> <h1>测试JSTL格式化日期标签</h1><br> today(default):<fmt:formatDate value="${today }"/><br> today(type="date"):<fmt:formatDate value="${today }" type="date"/><br> today(type="time"):<fmt:formatDate value="${today }" type="time"/><br> today(type="both"):<fmt:formatDate value="${today }" type="both"/><br> today(dateStyle="short"):<fmt:formatDate value="${today }" dateStyle="short"/><br> today(dateStyle="medium"):<fmt:formatDate value="${today }" dateStyle="medium"/><br> today(dateStyle="long"):<fmt:formatDate value="${today }" dateStyle="long"/><br> today(dateStyle="full"):<fmt:formatDate value="${today }" dateStyle="full"/><br> today(pattern="yyyy/MM/dd HH:mm:ss"):<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss"/><br> ${currentDate}<br> <h1>测试格式化日期标签</h1> n(default):<fmt:formatNumber value="${n }"/><br> n(pattern="###,###,###.###"):<fmt:formatNumber value="${n }" pattern="###,###,###.###"/><br> n(pattern="###,###,###.0000"):<fmt:formatNumber value="${n }" pattern="###,###,###.0000"/><br> n(groupingUsed="false"):<fmt:formatNumber value="${n }" groupingUsed="false"/><br> n(maxIntegerDigits="12" minIntegerDigits="10" ):<fmt:formatNumber value="${n }" maxIntegerDigits="12" minIntegerDigits="10"/><br> n( maxFractionDigits="6" minFractionDigits="4" ):<fmt:formatNumber value="${n }" maxFractionDigits="6" minFractionDigits="4"/><br> n(type="currency"):<fmt:formatNumber value="${n }" type="currency"/><br> n(type="currency" currencySymbol="$"):<fmt:formatNumber value="${n }" type="currency" currencySymbol="$"/><br> n(type="percent"):<fmt:formatNumber value="${p }" type="percent" minFractionDigits="2" maxFractionDigits="2"/><br> </body> </html>
JstlFmtServlet
/** * */ package com.bjpowrnode.jstl; import java.io.IOException; import java.util.Date; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @ClassName:JstlFmtServlet * @Description:测试JSTL格式化库 * @author wm * @date 2016年2月15日下午7:47:32 */ public class JstlFmtServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("today", new Date()); request.setAttribute("n", 12345678.123); request.setAttribute("p", 0.1234567); request.getRequestDispatcher("/jstl_fmt.jsp").forward(request,response); } }
标签:
原文地址:http://www.cnblogs.com/wangmei/p/5194953.html