Android Date String Parse parseDate(String str, String parsePattern)

Here you can find the source of parseDate(String str, String parsePattern)

Description

parse Date

Declaration

public static Date parseDate(String str, String parsePattern)
         throws ParseException 

Method Source Code

//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final String[] parsePatterns = new String[] {
            "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd", "HH:mm",
            "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd", "yyyyMMdd" };

    public static Date parseDate(String str) throws ParseException {

        return parseDate(str, parsePatterns[1]);
    }// w w  w. j a v a  2 s.  c  om

    public static Date parseDate(String str, String parsePattern)
            throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat(parsePattern);
        Date date = null;
        try {
            date = format.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;

    }
}

Related

  1. parseDate(String dateValue)
  2. parseDate(String dateValue)
  3. parseDate(String dateValue, String[] dateFormats, Date startDate)
  4. parseDate(String dateValue, String[] dateFormats, Date startDate)
  5. parseDate(String str)
  6. parseDate(String str, String... parsePatterns)
  7. parseDate(String ts)
  8. parseDate(final String dateValue, String[] dateFormats)
  9. parseDate(final String dateValue, String[] dateFormats)