Jsp page introduces tag library: <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
1 Format the date
<fmt:formatDate value="${date}" pattern="yyyy-MM-dd"/>
where ${date} is the java.util.Date type data in the actual data
The "yyyy-MM-dd" in pattern="yyyy-MM-dd" can be defined according to the standard time format string,
You can display the time, minutes and seconds as "yyyy-MM-dd HH:mm:ss", pay attention to the upper and lower case
Date type conversion tag: <fmt:parseDate value="${param.date}" var="date" pattern="yyyy/MM/dd:HH:mm:ss>
<fmt:formatDate type="both" dateStyle="full" timeStyle="full" value="${currentTime}" /><br/>
type: can be time , date or both . Controls whether to generate only the time, only the date, or both.
dateStyle: Can be short, medium, long or full (default) . Controls the specific format used for printing dates.
timeStyle: Can be short, medium, long or full (default) . Controls the specific format used for printing times.
value: This is a value of type java.util.Date used to generate the date and time.
2 Format numbers
<fmt:formatDate value="${DATE1}" pattern="yyyy-MM-dd hh:mm:ss" type="date" dateStyle="long" />
<fmt:formatNumber value="${num}" pattern="#" type="number"/>
where ${num} is any basic data type data, pattern specifies the format of the current number, you can specify the format " # "
(only integer types), " #.# " (types with one decimal place), " ¥#,###.### " (with thousands separators, and "¥" types), etc.; type specifies the current The type of numbers, there are three types: number (numerical value), currency (currency), and percent (percentage).
<fmt:formatNumber> tag: used to format numbers
value: formatted number, the value can be an instance of String type or java.lang.Number type
type: formatted type, possible values include: currency (currency), number (number) and percentage (percent)
pattern: format Formatting mode
var: result storage variable
scope: scope of variable
maxIntegerDigits: specify the maximum value of the
formatted result minIntegerDigits: specify the minimum value of the formatted result
maxFractionDigits: specify the maximum value of the formatted result, with decimals
minFractionDigits: specify the formatted result minimum value with decimals
java formatted output:
DecimalFormat df = new DecimalFormat("format");
String fmt =df.format(double);
Symbol Meaning
0 One digit
# One digit, leading zeros and trailing zeros are not displayed
. Decimal point dividing position
, group separator position
- negative prefix
% Multiply by 100 and display the percent sign
any other sign Include the specified sign in the output string