When handling a date as a character string in a CSV file etc., I think that the date format is often YYYY-MM-DD
.
However, when you open a CSV file in Excel, it may be automatically changed to the Excel date format and 2020-09-02
may be overwritten with 2020/9/2
.
When importing the date format character string automatically converted by Excel with java.time.LocalDate
, it is necessary to specify the format with java.time.format.DateTimeFormatter
.
scala> import java.time.LocalDate
import java.time.LocalDate
scala> import java.time.format.DateTimeFormatter
import java.time.format.DateTimeFormatter
scala> val localDate = LocalDate.parse("2020/9/2", DateTimeFormatter.ofPattern("yyyy/M/d"));
localDate: java.time.LocalDate = 2020-09-02
Recommended Posts