27
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

String、Date、LocalDateの変換

Last updated at Posted at 2017-01-26

Stringjava.time.LocalDate に変換

static final private String DATE_FORMAT = "yyyy-MM-dd";

public static LocalDate string2LocalDate(final String date) {
  return LocalDate.parse(date, DateTimeFormatter.ofPattern(DATE_FORMAT));
}

java.util.Datejava.time.LocalDate に変換

public static LocalDate date2LocalDate(final Date date) {
  return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}

java.time.LocalDatejava.util.Date に変換

public static Date localDate2Date(final LocalDate localDate) {
  return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
27
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?