LocalDateTime to String as format yyyy-MM-dd HH:mm:ss - Java java.time

Java examples for java.time:LocalDateTime

Description

LocalDateTime to String as format yyyy-MM-dd HH:mm:ss

Demo Code


//package com.java2s;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Main {
    private static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";

    public static String toString(LocalDateTime localDateTime) {
        return DateTimeFormatter.ofPattern(DATE_TIME_PATTERN,
                Locale.GERMANY).format(localDateTime);
    }// w w  w  . j  a  v a 2  s . com
}

Related Tutorials