Java DateTimeFormatter parseDateTime(String dateTimeStr, String format)

Here you can find the source of parseDateTime(String dateTimeStr, String format)

Description

Parse date time based on format (e.g yyyy/MM/dd HH:mm:ss)

License

Open Source License

Parameter

Parameter Description
dateTimeStr a parameter

Declaration

public static LocalDateTime parseDateTime(String dateTimeStr, String format) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*from   w  w w. j  a  va 2 s  . c  om*/
     * Parse date time based on format (e.g yyyy/MM/dd HH:mm:ss)
     * 
     * @param dateTimeStr
     * @return
     */
    public static LocalDateTime parseDateTime(String dateTimeStr, String format) {

        LocalDateTime date = null;
        try {

            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
            date = LocalDateTime.parse(dateTimeStr, formatter);
        } catch (DateTimeParseException exc) {
            System.out.printf("%s is not parsable!%n %s", dateTimeStr, exc);
        }

        return date;

    }
}

Related

  1. parse(DateTimeFormatter formatter, String string)
  2. parse(final DateTimeFormatter formatter, final String value, final ZoneId zoneId)
  3. parse(String _date, String _format)
  4. parse(String format, String datetime)
  5. parseAndFormat(String date, DateTimeFormatter fromFormatter, DateTimeFormatter toFormatter)
  6. parseZoneDateTime(String value, DateTimeFormatter formatter)
  7. setDateFormat(String pattern)
  8. validateDate(String input, DateTimeFormatter formatter)