Skip to Content
author's profile photo Former Member
Former Member

format date in jsp

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.

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 23, 2008 at 12:16 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 23, 2008 at 10:13 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 23, 2008 at 10:36 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.