Java Data Type How to - Parse String '2014-W14-2' to LocalDate as ISO_WEEK_DATE








Question

We would like to know how to parse String '2014-W14-2' to LocalDate as ISO_WEEK_DATE.

Answer

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/* w w  w.  j av a2s. c o  m*/
public class Main {
  public static void main(String[] args) {
    LocalDate fromIsoWeekDate = LocalDate.parse("2014-W14-2", DateTimeFormatter.ISO_WEEK_DATE);
    
    System.out.println(fromIsoWeekDate);
  }
}

The code above generates the following result.