Java Parse Date parseDateTime(String format, String dateStr)

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

Description

Parses specified date string according to format.

License

Apache License

Parameter

Parameter Description
format format pattern, e.g. DATE_TIME_FORMAT_WITH_SECONDS.
dateStr string to parse.

Declaration

public static Date parseDateTime(String format, String dateStr) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    /**/*from www . java 2s. c  om*/
     * Parses specified date string according to format.
     *
     * @param format format pattern, e.g. DATE_TIME_FORMAT_WITH_SECONDS.
     * @param dateStr string to parse.
     */
    public static Date parseDateTime(String format, String dateStr) throws ParseException {
        if ((format == null) || (dateStr == null)) {
            return null;
        }

        SimpleDateFormat formatter = new SimpleDateFormat(format);
        formatter.setLenient(false);
        return formatter.parse(dateStr);
    }
}

Related

  1. parseDateTime(String dateTime)
  2. parseDateTime(String dateTimeStr)
  3. parseDateTime(String dateTimeString)
  4. parseDateTime(String dateTimeString)
  5. parseDateTime(String dateTimeString, String[] validFormats, String outputFormat)
  6. parseDateTime(String fullDateParam, String unixDateParam, Map request)
  7. parseDateTime(String s)
  8. parseDateTime(String s)
  9. parseDateTime(String s)