Parse string To LocalDateTime in format of dd-MM-yyyy HH:mm:ss - Java java.time

Java examples for java.time:LocalDateTime

Description

Parse string To LocalDateTime in format of dd-MM-yyyy HH:mm:ss

Demo Code


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

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

    public static LocalDateTime stringToDateTime(String date) {
        return stringToDateTime(date, DATETIME_PATTERN);
    }//from   w  w w .j a  v  a 2s.co m

    public static LocalDateTime stringToDateTime(String date, String pattern) {
        return LocalDateTime.parse(date,
                DateTimeFormatter.ofPattern(pattern));
    }
}

Related Tutorials