on 08-06-2012 4:28 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Anupam/bhaskar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.