# 字串的完整日期無法轉換為LocalDateTime Unable to obtain LocalDateTime from TemporalAccessor
###### tags: `LocalDateTime` `Java`
```
LocalDateTime createDate = null;
String day = "";
if (payMethodId == 1) {
day = "20221225";
final DateTimeFormatter formatter= DateTimeFormatter.ofPattern("yyyyMMdd");
createDate = LocalDateTime.parse(day,formatter).atStartOfDay();//yyyyMMdd
}
```
錯誤訊息
```
java.time.format.DateTimeParseException: Text '20221225' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to
2022-12-25 of type java.time.format.Parsed
```
網路上找到的解法

```
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate dt = LocalDate.parse("20140218", formatter);
```