java.util.Date stores the milliseconds since the Unix epoch. It is not formatted, hence formatting has no impact on the underlying Date value.
<code class="java">LocalDateTime ldt = LocalDateTime.now(); System.out.println(DateTimeFormatter.ofPattern("MM-dd-yyyy", Locale.ENGLISH).format(ldt));</code>
<code class="java">// Import ThreeTen Backport LocalDateTime ldt = LocalDateTime.now(); DateTimeFormatter f = DateTimeFormatter.ofPattern("MM-dd-yyyy"); String formattedDateTime = f.format(ldt);</code>
<code class="java">Date myDate = new Date(); SimpleDateFormat mdyFormat = new SimpleDateFormat("MM-dd-yyyy"); String mdy = mdyFormat.format(myDate);</code>
Note: Formatting does not alter the Date value itself.
The above is the detailed content of How to Convert a java.util.Date from yyyy-mm-dd to mm-dd-yyyy?. For more information, please follow other related articles on the PHP Chinese website!