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).
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3