Java examples for java.time:LocalDateTime
parse LocalDateTime using ISO_LOCAL_DATE_TIME format
//package com.java2s; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.Optional; public class Main { private static DateTimeFormatter DEFAULT_DATE_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE_TIME; public static Optional<LocalDateTime> parseLocalDateTime(String dateString){ try{//from w w w . j av a 2s .c o m return Optional.of(DEFAULT_DATE_FORMATTER.parse(dateString, LocalDateTime::from)); }catch(DateTimeParseException e){ return Optional.empty(); } } }