java.util.Date stores the milliseconds since the Unix epoch. It is not formatted, hence formatting has no impact on the underlying Date value.
LocalDateTime ldt = LocalDateTime.now();
System.out.println(DateTimeFormatter.ofPattern("MM-dd-yyyy", Locale.ENGLISH).format(ldt));
// Import ThreeTen Backport
LocalDateTime ldt = LocalDateTime.now();
DateTimeFormatter f = DateTimeFormatter.ofPattern("MM-dd-yyyy");
String formattedDateTime = f.format(ldt);
Date myDate = new Date();
SimpleDateFormat mdyFormat = new SimpleDateFormat("MM-dd-yyyy");
String mdy = mdyFormat.format(myDate);
Note: Formatting does not alter the Date value itself.
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