Import the date string automatically converted to Excel with java.time.LocalDate

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.

Import with java.time.LocalDate

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

Import the date string automatically converted to Excel with java.time.LocalDate
Set the date and time from the character string with POI
Automatically scroll the background with libGDX
How to get the current date as a string in yyyyMMdd format
Automatically assign date and build number for the day to Maven version
[Java] How to set the Date time to 00:00:00
How to get the date in java
[Java] Get the date with the LocalDateTime class
How to get the query string to actually issue when using PreparedStatement with JDBC
I tried to get the distance from the address string to the nearest station with ruby