cancel
Showing results for 
Search instead for 
Did you mean: 

Date conversion

former_member223432
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

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

Answers (2)

Answers (2)

former_member223432
Participant
0 Kudos

Thanks Anupam/bhaskar

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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/