博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
<s:date>标签
阅读量:6913 次
发布时间:2019-06-27

本文共 1910 字,大约阅读时间需要 6 分钟。

Data标签方便在页面进行格式化的日期输出。格式有多种可供选择。同时,还可以通过在properties属性文件中定义好”struts.date.format”参数的值,从而自定义格式输出。

Date标签包含三个属性,可以从下面的代码中感受一下,分别是

1、Name:
2、Nice:  指定是否输出指定日期与当前时刻之间的时差。
   可以设为true或者false,表示是否漂亮地显示日期,如果设置为true,那么将FORMAT属性将不会生效
3、Format
   (1)当nice="false"时,format属性将起作用,如:"yyyy- MM-dd hh:mm:ss",其中,y是年(year),M是月(Month),d是日(day),h是小时(hour,12小时制),H也是小  时(hour,24小时制),m是分钟(minute),s是秒(second)。
   (2)当format未设置时,将会使用默认的格式DateFormat.MEDIUM format

1.dateTag.jsp

<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
 <head>
  <title>Date Tag 示例</title>
 </head> 
 <body>
  <h2>显示当前的时间</h2>
  <table border="1" width="35%">
   <tr>
    <td><b>日期格式</b></td>
    <td><b>日期</b></td>
   </tr>  
   <tr>
    <td>Day/Month/Year</td>
    <td><s:date name="currentDate" format="dd/MM/yyyy" /></td>
   </tr>
   <tr>  
    <td>Month/Day/Year</td>
    <td><s:date name="currentDate" format="MM/dd/yyyy" /></td>
   </tr>  
   <tr>
    <td>Month/Day/Year</td>
    <td><s:date name="currentDate" format="MM/dd/yy" /></td>
   </tr>  
   <tr>
    <td>Month/Day/Year Hour<B>:</B>Minute</td>
    <td><s:date name="currentDate" format="MM/dd/yy hh:mm" /></td>
   </tr>  
   <tr>
    <td>Month/Day/Year Hour<B>:</B>Minute<B>:</B>Second</td>
    <td><s:date name="currentDate" format="MM/dd/yy hh:mm:ss" /></td>
   </tr>  
   <tr>
    <td>Nice Date (Current Date & Time)</td>
    <td><s:date name="currentDate" nice="false" /></td>
   </tr>  
   <tr>
    <td>Nice Date</td>
    <td><s:date name="currentDate" nice="true" /></td>
   </tr>
  </table>
 </body>
</html>
2.DateTag.java
public class DateTag extends ActionSupport {
 
 private Date currentDate;

 public Date getCurrentDate() {

  return currentDate;
 }

 public void setCurrentDate(Date currentDate) {

  this.currentDate = currentDate;
 }
 
 public String execute(){
  currentDate = new Date();
  return SUCCESS;
 }
}

3.struts.xml

<action name="dateTag" class = "test1.DateTag">
 <result name="success">/test1/dateTag.jsp</result>
</action>

转载于:https://www.cnblogs.com/norsnake/archive/2013/01/23/2873706.html

你可能感兴趣的文章
用python实现计算1-2*((60-30+(-40/5)*(9-2*5/3+7/3*99/4*2998+10*568/14))-(-4*3)/(16-3*2))类似的公式计算...
查看>>
C#中事件的继承
查看>>
Context Switch Definition
查看>>
VS2015 Git 插件使用教程
查看>>
【转】iOS静态库 【.a 和framework】【超详细】
查看>>
iOS10 UI教程视图和子视图的可见性
查看>>
微信公众平台中的openid是什么?
查看>>
数据库三个范式详解
查看>>
使用JSON Web Token设计单点登录系统--转
查看>>
对于PHP中enum的好奇
查看>>
守护进程监控tomcat并自己主动重新启动
查看>>
协程基础_context系列函数
查看>>
排序算法总结之折半插入排序
查看>>
Simple calculations
查看>>
python list的+,+=,append,extend
查看>>
MySQL架构组成之逻辑模块组成
查看>>
DuiVision开发教程(19)-菜单
查看>>
Spark Streaming中的操作函数讲解
查看>>
长尾理论,长尾示意图,读书笔记
查看>>
Testing Is the Engineering Rigor of Software Development
查看>>