Home Struts Struts Struts2.2.1 struts2.2.1 date Format example

Ask Questions?

View Latest Questions


 
 

struts2.2.1 date Format example
Posted on: February 7, 2011 at 12:00 AM
Advertisement
In this example, We will discuss about the different type of date format using struts2.2.1.

struts2.2.1 date Format example.

In this example, We will discuss about the different type of date format using struts2.2.1.

Directory structure of example.

 1- index.jsp  

<html>

<head>

<title>Date Format Example</title>

</head>

<body>

<h2>Date Format Example</h2>

<hr>Current date

<a href="CurrenDate.action">Current date</a>

<hr> Date in different format

<a href="CurrenDateInDiffFormat.action">CurrenDateInDiffFormat</a>

</body>

</html>

2-DateAction.java

package roseindia.action;

import java.util.Calendar;

import java.util.Date;

import com.opensymphony.xwork2.ActionSupport;

public class DateAction extends ActionSupport {

private Date currentDate = new Date();

private Date pastDate;

private Calendar caldate = Calendar.getInstance();

public String execute() {

caldate.set(1986, 9, 25);

pastDate = caldate.getTime();

return SUCCESS;

}

public Date getCurrentDate() {

return currentDate;

}

public Date getPastDate() {

return pastDate;

}

public void setPastDate(Date pastDate) {

this.pastDate = pastDate;

}

}

3-CurrentDate.jsp

<%@taglib uri="/struts-tags" prefix="s"%>

<html>

<head>

<title>Date Format Example</title>

</head>

<body>

<h2>Date Format Example</h2>

<hr>

Current Date :

<s:date name="currentDate" format="yyyy-MM-dd"></s:date>

<hr>

Date in different format

<a href="CurrenDateInDiffFormat.action">Current Date In Different

Format</a>

</body>

</html>

4 struts.xml

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />

<constant name="struts.devMode" value="false" />

<package name="roseindia" extends="struts-default" namespace="/" >

<action name="CurrenDate" class="roseindia.action.DateAction">

<result name="success">/jsp/CurrentDate.jsp</result>

</action>

<action name="CurrenDateInDiffFormat" class="roseindia.action.DateAction">

<result name="success">/jsp/DateInDifferentFormat.jsp</result>

</action>

</package>

</struts>

5 DateInDifferentFormat.jsp

<%@ taglib uri="/struts-tags" prefix="s" %>

<html>

<head>

<title>DateFormatExample </title>

</head>

<body>

Current Date :

<s:date name="currentDate" format="yyyy-MM-dd"></s:date>

<h2>Date Format Example</h2>

<hr>

<b>Date Format(EEEE yyyy-MM-dd):</b><br/><br/>

<s:date name="pastDate" format="EEEE yyyy-MM-dd" />

<hr>

<b>Date Format (EEEE MM/dd/yyyy hh:mm AM/PM):</b><br/><br/>

<s:date name="pastDate" format="EEEE MM/dd/yyyy 'at' hh:mm a" />

<hr>

<b>Date Format (EEEE dd-MMM-yyyy hh:mm AM/PM) :</b><br/><br/>

<s:date name="pastDate" format="EEEE dd-MMM-yyyy 'at' hh:mm a" />

<hr>

<b> Format (EEEE dd/MM/yyyy hh:mm) :</b><br/><br/>

<s:date name="pastDate" format="EEEE dd/MM/yyyy hh:mm" />

<hr>

<b>Date Format(Nice):</b><br/><br/>

<s:date name="pastDate" format="yyyy-MM-dd" nice="true"/>

<hr>

</body>

</html>

 

index.jsp

currentDate.jsp

StrutsExample.gif

Download Select Source Code

Related Tags for struts2.2.1 date Format example:


DMCA.com