Java format LocalDateTime to yyyy/MM/dd HH:mm:ss

In this source code example, we will you how to format a LocalDateTime into yyyy/MM/dd HH:mm:ss format in Java.

Java format LocalDateTime to yyyy/MM/dd HH:mm:ss

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

public class Main {

    public static void main(String[] args) {

        // yyyy-MM-dd HH:mm:ss
        LocalDateTime localDateTime =;
        DateTimeFormatter formatterLocalDateTime = 
                DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        String ldt1 = formatterLocalDateTime.format(localDateTime);

        // or shortly
        String ldt2 =
                .format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));



2021/11/10 17:24:16
2021/11/10 17:24:16

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course