Anil's Blog is Best Viewed on GOOGLE CHROME

Wednesday, April 1, 2009

Change the date Format from YYYY-MM-DD to DD-MM-YYYY

In Controller

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.text.DateFormat;
import java.util.Date;

String newProjStartDate,newProjEndDate, sConvertNewStartDate, sConvertNewEndDate = null;


newProjStartDate= (String)pageContext.getSessionValue("newstartdate");
newProjEndDate= (String)pageContext.getSessionValue("newenddate");

try


{
DateFormat formatter ;
Date date, date1, date2, date3;
formatter = new SimpleDateFormat("yyyy-MM-dd");
date = formatter.parse(newProjStartDate);
date1 = formatter.parse(newProjEndDate);

pageContext.writeDiagnostics(this, "Anil date is =" + date, 1);
pageContext.writeDiagnostics(this, "Anil date1 is =" + date1, 1);

SimpleDateFormat formatterNew = new SimpleDateFormat("dd-MMM-yyyy");
sConvertNewStartDate=formatterNew.format(date);
sConvertNewEndDate=formatterNew.format(date1);

pageContext.writeDiagnostics(this, "sConvertStartDate date is =" + sConvertNewStartDate, 1);
pageContext.writeDiagnostics(this, "sConvertEndDate date1 is =" + sConvertNewEndDate, 1);

}

catch (ParseException e)

{
throw new IllegalArgumentException("Encountered Date format error "+ e);
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.