I have a string in the form MMM/dd/yyyy, ie. May/21/2010. Now I want to convert it to yyyyMMdd, ie. 20100521.
My code is:
public static void main(String[
Use SimpleDateFormat(String pattern, Locale locale) to add Locale
to your date parsing (for english, use Locale.ENGLISH
).
Better solution:
public String transformPrevDate(String datoe) {
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM/dd/yyyy", Locale.ENGLISH);
SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyyMMdd");
try {
return dateFormat2.format(dateFormat.parse(datoe));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}