Jstl number, date formatting
1. Formatting dates
<fmt:formatdate value= "${date1}" pattern= "Yyyy-mm-dd hh:mm:ss" type= "date" datestyle= "Long"/>
2. Formatting numbers
<fmt:formatdate value= "${date1}" pattern= "Yyyy-mm-dd hh:mm:ss" type= "date" datestyle= "Long"/>
Percent, thousand fractions indicate
<fmt:formatnumber value= "${doublevalue}" type= "Number" pattern= "0.00"/> 0.01‰<fmt:formatnumber valu E= "${doublevalue}" type= "number" pattern= "0.00%"/> 0.20
Other numbers indicate
Fmt:formatnumber value= "123456.7891" pattern= "#, #00.0#"/>--123,456.79
<fmt:formatnumber value= "123456.7" pattern= "#, #00.0#"/>--123,456.7
<fmt:formatnumber value= "123456.7" pattern= "#, #00.00#"/>--123,456.70
<fmt:formatnumber value= "" type= "percent"/>-1,200%type can be currency, number, and percent.
Currency representation
===1
<fmt:setlocale value= "Ch_ch"/>
<fmt:formatnumber value= "${data}" type= "Currency"/>
==2
<fmt:formatnumber value= "${doublevalue}" type= "number" pattern= "¥0.00"/>
Reference ==============================================================================
Java formatted output:
DecimalFormat df = new DecimalFormat ("format");
String FMT =df.format (double);
Symbolic meaning
01 Digits
# one digit, leading 0 and rear-end 0 not shown
. decimal point Split position
, the position of the group separator
-Negative prefix
% is used 100 times, and the percent sign is displayed
Any other symbol that includes the specified symbol in the output string
==================================================================================
<%@ page language= "java" contenttype= "text/html; charset=gb18030 "%>
<%@ 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>
=================================================================================
JSP internationalization-format currency and date
1. Formatted currency
Many countries in the world have different currency formats and number format conventions. Proper formatting and display of currency 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"%>
<title>currency formatting</title>
<body>
<fmt:setlocale value= "en_GB"/>
<fmt:formatnumber type= "Currency" value= "80000"/><br/>
<fmt:setlocale value= "en_US"/>
<fmt:formatnumber type= "Currency" value= "80000"/><br/>
<fmt:setlocale value= "Fr_fr"/>
<fmt:formatnumber type= "Currency" value= "80000"/><br/>
<fmt:setlocale value= "Ja_jp"/>
<fmt:formatnumber type= "Currency" value= "80000"/><br/>
<fmt:setlocale value= "Ko_kr"/>
<fmt:formatnumber type= "Currency" value= "80000"/><br/>
<fmt:setlocale value= "Es_es"/>
<fmt:formatnumber type= "Currency" value= "80000"/><br/>
<fmt:setlocale value= "Ar_eg"/>
<fmt:formatnumber type= "Currency" value= "80000"/><br/>
<fmt:setlocale value= "en_GB"/>
<fmt:formatnumber type= "Currency" value= "80000"/><br/>
<fmt:formatnumber type= "Currency" value= "80000" currencycode= "EUR"/><br/>
</body>
2. Formatting dates
Similar to digital and currency formatting, the localized environment also affects how 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"%>
<title>date formatting</title>
<body>
<fmt:timezone value= "EST" >
<jsp:usebean id= "CurrentTime" class= "Java.util.Date"/>
<fmt:setlocale value= "en_GB"/>
<fmt:formatdate type= "Both" datestyle= "full" timestyle= "full" value= "${currenttime}"/><br/>
<fmt:setlocale value= "en_US"/>
<fmt:formatdate type= "Both" datestyle= "full" timestyle= "full" value= "${currenttime}"/><br/>
<fmt:setlocale value= "Fr_fr"/>
<fmt:formatdate type= "Both" datestyle= "full" timestyle= "full" value= "${currenttime}"/><br/>
<fmt:setlocale value= "Ja_jp"/>
<fmt:formatdate type= "Both" datestyle= "full" timestyle= "full" value= "${currenttime}"/><br/>
<fmt:setlocale value= "Ko_kr"/>
<fmt:formatdate type= "Both" datestyle= "full" timestyle= "full" value= "${currenttime}"/><br/>
<fmt:setlocale value= "Es_es"/>
<fmt:formatdate type= "Both" datestyle= "full" timestyle= "full" value= "${currenttime}"/><br/>
<fmt:setlocale value= "Ar_eg"/>
<fmt:formatdate type= "Both" datestyle= "full" timestyle= "full" value= "${currenttime}"/><br/>
</fmt:timeZone>
</body>
Properties of the <fmt:formatDate> action
Type: can be time,date or both. Controls whether only the time is generated, the date is generated, or the time date is generated.
Datestyle: Can be short, medium, long or full (default). Controls the specific format used for the print date.
Timestyle: Can be short, medium, long or full (default). Controls the specific format used for printing time.
Value: This is a java.util.Date type that is used to generate the date and time.
Tribute to the original author of the article!
--------------------------------------------------------------------------
If a struts tag can use formatkey= "" to format a number
such as: <bean:write name= "Vo" property= "JSJG" bundle= "constant" formatkey= "Format.decimal.amtTwo"/>
Format.decimal.amtTwo defining the output format in the resource file (format.decimal.amttwo=/#,/#/#/#.00/#/#/#/#) retains two decimal places
Number reserved two-bit
<fmt:formatnumber value= "${vo.amount-vo.usedamount}" pattern= "#,# #0.00#"/> (If using pattern= "#, #00.00#") Cannot format a number under 101
Jstl number, date formatting