fork(5) download
  1. import java.time.LocalDate;
  2. import java.time.LocalDateTime;
  3. import java.time.format.DateTimeFormatter;
  4. import java.util.Locale;
  5.  
  6. public class Main {
  7. public static void main(String[] args) {
  8. String strDate = "2011-01-18 00:00:00.0";
  9. DateTimeFormatter dtfInput = DateTimeFormatter.ofPattern("u-M-d H:m:s.S", Locale.ENGLISH);
  10. LocalDateTime ldt = LocalDateTime.parse(strDate, dtfInput);
  11. // Alternatively, the old way:
  12. // LocalDateTime ldt = dtfInput.parse(strDate, LocalDateTime::from);
  13.  
  14. LocalDate date = ldt.toLocalDate();
  15. System.out.println(date);
  16. }
  17. }
  18.  
Success #stdin #stdout 0.1s 49228KB
stdin
Standard input is empty
stdout
2011-01-18