rasi rasi - 9 months ago 26
Java Question

How can I change the date format in Java?

I need to change the date format using Java from

dd/MM/yyyy to yyyy/MM/dd


How to convert from one date format to another using SimpleDateFormat:

final String OLD_FORMAT = "dd/MM/yyyy";
final String NEW_FORMAT = "yyyy/MM/dd";

// August 12, 2010
String oldDateString = "12/08/2010";
String newDateString;

SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
Date d = sdf.parse(oldDateString);
newDateString = sdf.format(d);