rasi rasi - 1 year ago 70
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

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download