Java Parse Date Pattern YYYY parseStringToDate(final String pDate, final String... pFormat)

Here you can find the source of parseStringToDate(final String pDate, final String... pFormat)

Description

parse String To Date

License

Apache License

Declaration

public static Date parseStringToDate(final String pDate, final String... pFormat) 

Method Source Code


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

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

public class Main {
    private static final String DEFAULT_FORMAT = "yyyy-MM-dd";
    private static final int FORMAT_POSITION = 0;

    public static Date parseStringToDate(final String pDate, final String... pFormat) {
        final DateFormat dateFormat;
        if (pFormat.length == 0) {
            dateFormat = new SimpleDateFormat(DEFAULT_FORMAT);
        } else {/*  w  ww. j  a  v a 2s .c  om*/
            dateFormat = new SimpleDateFormat(pFormat[FORMAT_POSITION]);
        }
        final Date parsedDate;
        try {
            parsedDate = dateFormat.parse(pDate);
        } catch (ParseException pEx) {
            return null;
        }
        return parsedDate;
    }
}

Related

  1. parseStringAsDate(String pattern, String value)
  2. parseStringDate(String dateAsString)
  3. parseStringDateToRmFormat(String date)
  4. parseStringForDate(String dateString)
  5. parseStringToCalendar(String strDate)
  6. parseStringToDate(String date)
  7. parseStringToDate(String dateString)
  8. parseStringToDatePrettyPrint(Date date)
  9. parseStringToUtilDate(String strDate)