jstl <fmt:formatDate>标签

<fmt:formatDate>标记用于在各种不同的方式来格式化日期

属性:

<fmt:formatDate>标签具有以下属性:

属性描述必需默认值
value要显示的日期值YesNone
typeDATE, TIME, or BOTHNodate
dateStyleFULL, LONG, MEDIUM, SHORT, or DEFAULTNodefault
timeStyleFULL, LONG, MEDIUM, SHORT, or DEFAULTNodefault
patternCustom formatting patternNoNone
timeZoneTime zone of the displayed dateNoDefault time zone
varName of the variable to store the formatted dateNoPrint to page
scopeScope of the variable to store the formatted dateNopage

pattern属性来指定更精确的处理日期:

CodePurposeSample

G

The era designator

AD

y

The year

2002

M

The month

April & 04

d

The day of the month

20

h

The hour(12-hour time)

12

H

The hour(24-hour time)

0

m

The minute

45

s

The second

52

S

The millisecond

970

E

The day of the week

Tuesday

D

The day of the year

180

F

The day of the week in the month

2 (2nd Wed in month)

w

The week in the year

27

W

The week in the month

2

a

The a.m./p.m. indicator

PM

k

The hour(12-hour time)

24

K

The hour(24-hour time)

0

z

The time zone

Central Standard Time

'

 

The escape for text

''

 

The single quote

例子:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>
  <title>JSTL fmt:dateNumber Tag - www.yiibai.com</title>
</head>
<body>
<h3>Number Format:</h3>
<c:set var="now" value="<%=new java.util.Date()%>" />

<p>Formatted Date (1): <fmt:formatDate type="time" 
            value="${now}" /></p>
<p>Formatted Date (2): <fmt:formatDate type="date" 
            value="${now}" /></p>
<p>Formatted Date (3): <fmt:formatDate type="both" 
            value="${now}" /></p>
<p>Formatted Date (4): <fmt:formatDate type="both" 
            dateStyle="short" timeStyle="short" 
            value="${now}" /></p>
<p>Formatted Date (5): <fmt:formatDate type="both" 
            dateStyle="medium" timeStyle="medium" 
            value="${now}" /></p>
<p>Formatted Date (6): <fmt:formatDate type="both" 
            dateStyle="long" timeStyle="long" 
            value="${now}" /></p>
<p>Formatted Date (7): <fmt:formatDate pattern="yyyy-MM-dd" 
            value="${now}" /></p>

</body>
</html>

这将产生以下结果:

Date Format:

Formatted Date (1): 14:27:18

Formatted Date (2): 23-Sep-2010

Formatted Date (3): 23-Sep-2010 14:27:18

Formatted Date (4): 23/09/10 14:27

Formatted Date (5): 23-Sep-2010 14:27:18

Formatted Date (6): 23 September 2010 14:27:18 GST

Formatted Date (7): 2010-09-23

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值