cancel
Showing results for 
Search instead for 
Did you mean: 

format date in jsp

Former Member
0 Kudos

I have a date in yyyy-mm-dd format stored in a string.

I want to display the date in dd-mmm-yyyy format in jsp.

please provide me the code for the same.

Get 10 pts for right answer.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi anzar naik,

Try this,

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-YYYY");

Date beforeDate=null;

beforeDate=sdf.parse(Your_Date);

Hope it will help you. Thanks.

Regards,

Kathiresan R

Note:

Points are welcome

Answers (2)

Answers (2)

srinivas_sistu
Active Contributor
0 Kudos

Hi,

you can try this way...

SimpleDateFormat dateFormat;

dateFormat = new SimpleDateFormat("dd-MMM-yyyy"); //format can be dd-MM-yy or dd-MM-yyyy also

String strformatteddate=dateFormat.format(Your Date to be formatted);

but it returns date in string format...

Regards,

Srinivas.

Former Member
0 Kudos

you could try something like this

public class ChangeData

{

public static void main(String args[])

{

String initDate = "yyyy-mm-dd";

String newDate = "";

String a,b,c;

a = initDate.substring(initDate.lastIndexOf("-")+1);

b = initDate.substring(0,initDate.indexOf("-"));

c = initDate.substring(initDate.indexOf("-")+1,initDate.lastIndexOf("-"));

newDate = a"-"c"-"b;

System.out.println(newDate);

}

}//dd-mmm-yyyy

now do note that this code will only work if the input is always in the form of "yyyy-mm-dd"

Thanks,

GLM