Time Formatting tags

Source: Internet
Author: User
Tags java format

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<%@ taglib uri= "http://java.sun.com/jsp/jstl/fmt" prefix= "FMT"%>
<%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>
<title>my JSP ' fmt.jsp ' starting page</title>

<body>
<c:set var= "Salary" value= "3540.2301"/>
<c:set var= "Total" value= "56225.2301"/>
<fmt:setlocale value= "en_US"/>
Currency:<fmt:formatnumber value= "${salary}" type= "Currency" currencycode= "USD"/><br>
Percent:<fmt:formatnumber value= "${salary/total}" type= "percent" maxfractiondigits= "4"/><br>
<jsp:usebean id= "Now" class= "Java.util.Date" ></jsp:useBean>
<fmt:setlocale value= "Zh_cn"/>
Full--><fmt:formatdate value= "${now}" type= "both" datestyle= "full" timestyle= "full"/><br>
Long--><fmt:formatdate value= "${now}" type= "both" datestyle= "long" timestyle= "Long"/><br>
Medium--><fmt:formatdate value= "${now}" type= "both" datestyle= "Medium" timestyle= "Medium"/><br>
Default--><fmt:formatdate value= "${now}" type= "both" datestyle= "default" timestyle= "Default"/><br>
Short--><fmt:formatdate value= "${now}" type= "both" datestyle= "short" timestyle= "short"/><br>
</body>

Today is: <fmt:formatdate value= "${now}" pattern= "G yyyy year mm DD Day E"/><br>
Now: <fmt:formatdate value= "${now}" pattern= "a HH:mm:ss. S Z "/>
Results:
Today is: October 19, 2007 A.D. Friday
Now is: PM 20:04:11.484 CST

<%@ taglib prefix= "C" uri= "Http://java.sun.com/jstl/core"%>
<%@ taglib prefix= "FMT" uri= "Http://java.sun.com/jstl/fmt"%>

<fmt:parsedate value= "${param.date}" var= "date" pattern= "yyyy/mm/dd:hh:mm:ss>
<fmt:parsedate value= "${param.isodate}" var= "Isodate" pattern= "YyyyMMdd ' T ' Hhmmss" >

The input parameters must match the patterns, or the JSP would thrown an exception. This page does no error handling.

Input Parameters:
date:2004/04/01:13:30:00 Java Format:thu Apr 13:30:00 CST 2004
isodate:20040531t235959 Java Format:mon 23:59:59 CDT 2004

Dates
Tag Output
Attribute:value; Required. Tag has no body.
<fmt:formatdate value= "${date}" type= "both"/>

2004-4-1 13:30:00
<fmt:formatdate value= "${isodate}" type= "both"/>

2004-5-31 23:59:59
Attribute:type; Optional. Indicates to Print:date, time, or both.
<fmt:formatdate value= "${date}" type= "date"/>

2004-4-1
<fmt:formatdate value= "${isodate}" type= "Time"/>

23:59:59
Attribute:datestyle; Optional. varies the date format.
<fmt:formatdate value= "${isodate}" type= "date" datestyle= "Default"/>

2004-5-31
<fmt:formatdate value= "${isodate}" type= "date" datestyle= "short"/>

04-5-31
<fmt:formatdate value= "${isodate}" type= "date" datestyle= "Medium"/>

2004-5-31
<fmt:formatdate value= "${isodate}" type= "date" datestyle= "Long"/>

May 31, 2004
<fmt:formatdate value= "${isodate}" type= "date" datestyle= "full"/>

Monday, May 31, 2004
Attribute:timestyle; Optional. varies the time format.
<fmt:formatdate value= "${isodate}" type= "Time" timestyle= "Default"/>

23:59:59
<fmt:formatdate value= "${isodate}" type= "Time" timestyle= "short"/>

11:59
<fmt:formatdate value= "${isodate}" type= "Time" timestyle= "Medium"/>

23:59:59
<fmt:formatdate value= "${isodate}" type= "Time" timestyle= "Long"/>

11:59 P.M. 59 sec
<fmt:formatdate value= "${isodate}" type= "Time" timestyle= "full"/>

11:59 P.M. 59 sec. CDT
Attribute:pattern; Optional. Inidcates Date/time Custom Patterns.
<fmt:formatdate value= "${date}" type= "both" pattern= "eeee, MMMM D, yyyy HH:mm:ss Z"/>

Thursday, April 1, 2004 13:30:00-0600
<fmt:formatdate value= "${isodate}" type= "both" pattern= "D MMM yy, h:m:s a zzzz/>

<fmt:formatdate value= "${here can put date and string}" pattern= "yyyy year MM DD Day"/

Time Formatting tags

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.