Changing Date Format in Java: Transforming dd/MM/yyyy to yyyy/MM/dd
To alter the date format from dd/MM/yyyy to yyyy/MM/dd in Java, you can utilize the SimpleDateFormat class. Here's how to proceed:
final String OLD_FORMAT = "dd/MM/yyyy"; final String NEW_FORMAT = "yyyy/MM/dd";
String oldDateString = "12/08/2010"; // Assuming August 12, 2010
SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
Date d = sdf.parse(oldDateString);
sdf.applyPattern(NEW_FORMAT);
String newDateString = sdf.format(d);
This approach allows you to successfully convert the date string from the original format (dd/MM/yyyy) to the desired format (yyyy/MM/dd).
The above is the detailed content of How to Convert dd/MM/yyyy to yyyy/MM/dd Date Format in Java?. For more information, please follow other related articles on the PHP Chinese website!