fmt:formatDate标签的输出格式

本文详细介绍了fmt:formatDate标签在日期和时间格式化方面的使用方法,包括各种输出样式和模式参数,通过示例展示了如何灵活配置日期、时间的展示方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<fmt:formatDate>标签的输出格式:
  d   月中的某一天。一位数的日期没有前导零。    
  dd   月中的某一天。一位数的日期有一个前导零。    
  ddd   周中某天的缩写名称,在   AbbreviatedDayNames   中定义。    
  dddd   周中某天的完整名称,在   DayNames   中定义。    
  M   月份数字。一位数的月份没有前导零。    
  MM   月份数字。一位数的月份有一个前导零。    
  MMM   月份的缩写名称,在   AbbreviatedMonthNames   中定义。    
  MMMM   月份的完整名称,在   MonthNames   中定义。    
  y   不包含纪元的年份。如果不包含纪元的年份小于   10,则显示不具有前导零的年份。    
  yy   不包含纪元的年份。如果不包含纪元的年份小于   10,则显示具有前导零的年份。    
  yyyy   包括纪元的四位数的年份。    
  gg   时期或纪元。如果要设置格式的日期不具有关联的时期或纪元字符串,则忽略该模式。    
  h   12   小时制的小时。一位数的小时数没有前导零。从112,分上下午 范围:0100                          AM~12:59AM    
  hh   12   小时制的小时。一位数的小时数有前导零。    
  H   24   小时制的小时。一位数的小时数没有前导零。从023,范围:0000 AM~23:59AM    
  HH   24   小时制的小时。一位数的小时数有前导零。    
  m   分钟。一位数的分钟数没有前导零。    
  mm   分钟。一位数的分钟数有一个前导零。    
  s   秒。一位数的秒数没有前导零。    
  ss   秒。一位数的秒数有一个前导零。

  

示例:index.jsp 

[java] view plaincopy

 

{type:both}  <fmt:formatDate value="<%=new Date() %>" type="both"/><!-- 2011-3-30 9:41:21 -->     

<br/>     

{type:date}  <fmt:formatDate value="<%=new Date() %>" type="date"/><!-- 2011-3-30 -->     

<br/>     

{type:time}  <fmt:formatDate value="<%=new Date() %>" type="time"/><!-- 9:44:44 -->     

<br/>     

{type:date, dateStyle:default}  <fmt:formatDate value="<%=new Date() %>" type="date" dateStyle="default"/><!-- 2011-3-30 -->     

<br/>     

{type:date, dateStyle:short}  <fmt:formatDate value="<%=new Date() %>" type="date" dateStyle="short"/><!-- 11-3-30  -->     

10 <br/>     

11 {type:date, dateStyle:medium}  <fmt:formatDate value="<%=new Date() %>" type="date" dateStyle="medium"/><!-- 2011-3-30 -->     

12 <br/>     

13 {type:date, dateStyle:long}  <fmt:formatDate value="<%=new Date() %>" type="date" dateStyle="long"/><!-- 2011330日 -->     

14 <br/>     

15 {type:date, dateStyle:full}  <fmt:formatDate value="<%=new Date() %>" type="date" dateStyle="full"/><!-- 2011330日 星期三 -->     

16  <br/>     

17 {type:time, timeStyle:default}  <fmt:formatDate value="<%=new Date() %>" type="time" timeStyle="default"/><!-- 10:01:32  -->     

18 <br/>     

19 {type:time, timeStyle:short}  <fmt:formatDate value="<%=new Date() %>" type="time" timeStyle="short"/><!-- 上午10:01  -->     

20 <br/>     

21 {type:time, timeStyle:medium}  <fmt:formatDate value="<%=new Date() %>" type="time" timeStyle="medium"/><!-- 10:01:32 -->     

22 <br/>     

23 {type:time, timeStyle:long}  <fmt:formatDate value="<%=new Date() %>" type="time" timeStyle="long"/><!-- 上午100132秒 -->     

24 <br/>     

25 {type:time, timeStyle:full}  <fmt:formatDate value="<%=new Date() %>" type="time" timeStyle="full"/><!-- 上午100132秒 CST  -->     

26 <br/>     

27 {type:both, pattern:EEEE, MMMM d, yyyy HH:mm:ss Z}  <fmt:formatDate value="<%=new Date() %>" type="both" pattern="EEEE, MMMM d, yyyy HH:mm:ss Z"/><!-- 星期三三月 302011 10:01:32 +0800  -->     

28 <br/>     

29 {type:both, pattern:d MMM yy, h:m:s a zzzz}  <fmt:formatDate value="<%=new Date() %>" type="both" pattern="d MMM yy, h:m:s a zzzz"/><!-- 30 三月 1110:1:32 上午 中国标准时间 -->     

30 <br/>     

31 {pattern:dd/MM/yyyy HH:mm aa}}  <fmt:formatDate value="<%=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-3-30 13:12:12") %>" pattern="dd/MM/yyyy HH:mm aa"/><!-- 30/03/2011 13:12 下午 -->     

32 <br/>     

33 {pattern:dd/MM/yyyy hh:mm aa}  <fmt:formatDate value="<%=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-3-30 13:12:12") %>" pattern="dd/MM/yyyy hh:mm aa"/><!-- 30/03/2011 01:12 下午 -->    

显示结果:

{type:both}  2011-3-30 10:07:42
{type:date}  2011-3-30
{type:time}  10:07:42
{type:date, dateStyle:default}  2011-3-30
{type:date, dateStyle:short}  11-3-30
{type:date, dateStyle:medium}  2011-3-30
{type:date, dateStyle:long}  2011330
{type:date, dateStyle:full}  2011330日 星期三
{type:time, timeStyle:default}  10:07:42
{type:time, timeStyle:short}  上午10:07
{type:time, timeStyle:medium}  10:07:42
{type:time, timeStyle:long}  上午100742
{type:time, timeStyle:full}  上午100742秒 CST
{type:both, pattern:EEEE, MMMM d, yyyy HH:mm:ss Z}  星期三三月 30, 2011 10:07:42 +0800
{type:both, pattern:d MMM yy, h:m:s a zzzz}  30 三月 11, 10:7:42 上午 中国标准时间
{pattern:dd/MM/yyyy HH:mm aa}  30/03/2011 13:12 下午
{pattern:dd/MM/yyyy hh:mm aa}  30/03/2011 01:12 下午

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值