parses string exclusively in this format "dd/mm/yyyy HH:mm" to LocalDateTime - Java java.time

Java examples for java.time:LocalDateTime

Description

parses string exclusively in this format "dd/mm/yyyy HH:mm" to LocalDateTime

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_TIME_FORMATTER = DateTimeFormatter
            .ofPattern("dd/MM/yyyy HH:mm");

    /*** Methods ***/
    // parses string exclusively in this format "dd/mm/yyyy HH:mm"
    public static LocalDateTime parseStringToDateTime(String inputString) {
        try {/*from  ww  w. j a  va2  s .  co m*/
            return LocalDateTime.parse(inputString, DATE_TIME_FORMATTER);
        } catch (DateTimeException e) {
            return null;
        }
    }
}

Related Tutorials