Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

tag

fmt:formatDate tag

JSP Standard Label LibraryJSP Standard Tag Library

fmt:formatDateThe tag is used to format dates in different ways.

Syntax format





property

fmt:formatDateThe tag has the following attributes:

property Description Whether it is required Default value
value The date to display Is None
type DATE, TIME, or BOTH No date
dateStyle FULL, LONG, MEDIUM, SHORT, or DEFAULT No default
timeStyle FULL, LONG, MEDIUM, SHORT, or DEFAULT No default
pattern A custom format pattern No None
timeZone The time zone in which to display the date No The default time zone
var The name of the variable that stores the formatted date No Display on the page
scope The scope for storing the formatted date variable No Page

fmt:formatDate tag format patterns

Code Description Example

G

Era designator

AD

y

Year without era. If the year without era is less than 10, the year is displayed without a leading zero.

2002

M

Month as a number. Single-digit months have no leading zero.

April & 04

d

Day of the month. Single-digit days have no leading zero.

20

h

Hour in 12-hour format. Single-digit hours have no leading zero.

12

H

Hour in 24-hour format. Single-digit hours have no leading zero.

0

m

Minute. Single-digit minutes have no leading zero.

45

s

Second. Single-digit seconds have no leading zero.

52

S

Millisecond

970

E

Day of the week

Tuesday

D

Day of the year

180

F

The nth day of the week in a month

2 (the second Wednesday of the month)

w

Week of the year r

27

W

Week of the month

2

a

a.m./p.m. designator

PM

k

Hour (12-hour format)

24

K

Hour (24-hour format)

0

z

Timezone

Central Standard Time

'

 

Escaped text

''

 

Single quote


Example Demonstration



<%@ 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" %>







  JSTL fmt:dateNumber 标签





日期格式化:

日期格式化 (1):

日期格式化 (2):

日期格式化 (3):

日期格式化 (4):

日期格式化 (5):

日期格式化 (6):

日期格式化 (7):

The result of the above example:



Date Formatting:



日期格式化 (1): 11:19:43



日期格式化 (2): 2016-6-26



日期格式化 (3): 2016-6-26 11:19:43



日期格式化 (4): 16-6-26 上午11:19



日期格式化 (5): 2016-6-26 11:19:43



日期格式化 (6): 2016年6月26日 上午11时19分43秒



日期格式化 (7): 2016-06-26


JSP Standard Label LibraryJSP Standard Tag Library