format LocalDateTime Date Time - Java java.time

Java examples for java.time:LocalDateTime

Description

format LocalDateTime Date Time

Demo Code


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;

public class Main{
    private static final DateTimeFormatter FMT = new DateTimeFormatterBuilder()
            .appendPattern(PATTERN).toFormatter();
    public static String formatDateTime(LocalDateTime dateTime) {
        String text = "";
        if (dateTime != null) {
            return dateTime.format(FMT);
        }//from  w w w  .  j ava  2s . com
        return text;
    }
}

Related Tutorials