Skip to Content

Date conversion

Hi,

I have scenario where i am using the below Logic to convert the date from dd-mm-yy to this format dd-MMM-yy

DateFormat df1 = new SimpleDateFormat("dd-mm-yy");
DateFormat df2 = new SimpleDateFormat("dd-MMM-yy");
String convertedDate = "";

try{
convertedDate = df2.format(df1.parse(currentDate));
}catch(Exception ex){}

return convertedDate;

but as an output i am always getting MMM as JAN...

is there anything wrong in the logic written

regards

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Aug 06, 2012 at 04:39 PM

    Hi Smith ,

    Try this code

    DateFormat df1 = new SimpleDateFormat("dd-MM-yy");
    DateFormat df2 = new SimpleDateFormat("dd-MMM-yy");
    String convertedDate = "";

    try{
    convertedDate = df2.format(df1.parse(currentDate));
    }catch(Exception ex){}

    return convertedDate;

    Regards

    Anupam

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 06, 2012 at 04:53 PM

    Anupam is right. The main flaw in your coding is you are using mm which refers minutes not Months. In java date format we need to use MM for month.

    You might also want to glance this link for understanding the date formats

    http://javatechniques.com/blog/dateformat-and-simpledateformat-examples/

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 06, 2012 at 04:58 PM

    Thanks Anupam/bhaskar

    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.