format LocalDateTime as ISO_LOCAL_DATE_TIME - Java java.time

Java examples for java.time:LocalDateTime

Description

format LocalDateTime as ISO_LOCAL_DATE_TIME

Demo Code


//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));
    }
}

Related Tutorials