Java examples for java.time:LocalDateTime
format LocalDateTime as ISO_LOCAL_DATE_TIME
//package com.java2s; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Optional; public class Main { private static DateTimeFormatter DEFAULT_DATE_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE_TIME; public static Optional<String> formatLocalDateTime(LocalDateTime date) { if (null == date) { return Optional.empty(); }/*from w w w . j a v a 2 s . c om*/ return Optional.of(DEFAULT_DATE_FORMATTER.format(date)); } }