Format LocalDateTime Date as dd/MM/yyyy - Java java.time

Java examples for java.time:LocalDateTime

Description

Format LocalDateTime Date as dd/MM/yyyy

Demo Code


//package com.java2s;
import java.time.DateTimeException;
import java.time.LocalDateTime;

import java.time.format.DateTimeFormatter;

public class Main {
    private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter
            .ofPattern("dd/MM/yyyy");

    public static String getDate(LocalDateTime inputDateTime) {
        try {/*from   w w w . j  a v  a  2  s . co m*/
            return inputDateTime.toLocalDate().format(DATE_FORMATTER);
        } catch (DateTimeException e) {
            return null;
        }
    }
}

Related Tutorials