2015-09-26 155 views
0

我有一個字符串「2015-09-17T12:00」。我如何將這個字符串轉換爲格式爲「yyyy-MM-dd HH:mm」的LocalDateTime,然後將其轉換回字符串?如何將字符串轉換爲LocalDateTime?

+5

可能重複的[Java字符串到日期轉換](http://stackoverflow.com/questions/4216745/java-string-to-date-conversion) – AsSiDe

+0

如何擺脫字符串中的「T」 。 – starblu3

+1

[DateTimeFormatter](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE_TIME)是否處理​​此問題? – MadProgrammer

回答

1

你可以用空格(S)更換T:

String str="2015-09-17T12:00"; 
str.replace("T"," "); 

之後轉換爲使用的SimpleDateFormat日期;