Java Parse Date parseDate(String dateString)

Here you can find the source of parseDate(String dateString)

Description

parse Date

License

Apache License

Declaration

public static Date parseDate(String dateString) 

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 {
    protected static final String _listFormat[] = { "", "", "" };

    public static Date parseDate(String dateString) {
        return parseDate(dateString, _listFormat);
    }/*ww w  .jav  a2 s  .  co  m*/

    public static Date parseDate(String dateString, String format) {
        String listFormat[] = new String[1];
        listFormat[0] = format;
        return parseDate(dateString, listFormat);
    }

    public static Date parseDate(String dateString, String[] formats) {
        Date date = null;
        for (String format : formats) {
            SimpleDateFormat dateFormat = new SimpleDateFormat(format);
            try {
                date = dateFormat.parse(dateString);
                break; // i.e. don't try further.
            } catch (ParseException e) {
            }
        }

        return date;
    }
}

Related

  1. parseDate(String dateStr, String... formats)
  2. parseDate(String dateString)
  3. parseDate(String dateString)
  4. parseDate(String dateString)
  5. parseDate(String dateString)
  6. parseDate(String dateString)
  7. parseDate(String dateString)
  8. parseDate(String dateString)
  9. parseDate(String dateString)