1 回答

TA貢獻1802條經(jīng)驗 獲得超10個贊
java.time
String dateString = "2019-06-01 00:15:00";
dateString = dateString.replace(" ", "T");
dateString = dateString.concat("Z");
DateTimeFormatter formatter = DateTimeFormatter
.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM)
.withLocale(Locale.FRENCH);
OffsetDateTime dateTime = OffsetDateTime.parse("2019-06-01T00:15:00Z");
String formattedDateTime = dateTime.format(formatter);
System.out.println("Formatted date/time: " + formattedDateTime);
輸出:
格式化日期/時間:01/06/2019 00:15:00
我建議你不要使用DateFormat. 該類是出了名的麻煩且早已過時。而是使用DateTimeFormatter現(xiàn)代 Java 日期和時間 API from java.time,如我的代碼所示。
對于您的代碼中出了什么問題,請參閱我在底部鏈接到的類似問題。
添加回答
舉報