Android Date String Parse parseDate(String value, String[] parsePatterns)

Here you can find the source of parseDate(String value, String[] parsePatterns)

Description

parse Date

Declaration

public static Date parseDate(String value, String[] parsePatterns)
            throws ParseException 

Method Source Code

//package com.java2s;

import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date parseDate(String value, String[] parsePatterns)
            throws ParseException {
        if (value == null || parsePatterns == null) {
            throw new IllegalArgumentException(
                    "Date and Patterns must not be null");
        }/*ww  w .j  a v  a 2s. c o  m*/

        SimpleDateFormat parser = null;
        ParsePosition pos = new ParsePosition(0);
        for (int i = 0; i < parsePatterns.length; i++) {
            if (i == 0) {
                parser = new SimpleDateFormat(parsePatterns[0]);
            } else {
                parser.applyPattern(parsePatterns[i]);
            }
            pos.setIndex(0);
            Date date = parser.parse(value, pos);
            if (date != null && pos.getIndex() == value.length()) {
                return date;
            }
        }
        throw new ParseException("Unable to parse the date: " + value, -1);
    }
}

Related

  1. parseTM(String s, boolean end)
  2. parseDate(String date)
  3. parse(String dateStr)
  4. parse(String input)
  5. parse(String source, String pattern)
  6. parseJsonDate(String jsonDate)
  7. str2Date(String str)
  8. stringConvertDate(String date)
  9. stringToDate(String date)