Java Parse Date parseDate(String dateString)

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

Description

Go over all date formats and try to format the given date string

License

Open Source License

Parameter

Parameter Description
dateString a parameter

Exception

Parameter Description
ParseException if no format matches

Declaration

public static Date parseDate(String dateString) throws ParseException 

Method Source Code


//package com.java2s;

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

import java.util.Date;

public class Main {
    public static final String[] DATE_FORMATS = new String[] { "dd/MM/yy, HH:mm:ss", "EEE MMM d hh:mm:ss z yyyy" };

    /**//from   www.ja  v  a 2 s  . c  o m
     * Go over all date formats and try to format the given date string
     * @param dateString   
     * @return
     * @throws ParseException   if no format matches
     */
    public static Date parseDate(String dateString) throws ParseException {
        ParseException exception = null;
        for (String format : DATE_FORMATS) {
            try {
                return new SimpleDateFormat(format).parse(dateString);
            } catch (ParseException e) {
                exception = e;
            }
        }
        throw exception;
    }
}

Related

  1. parseDate(String dateString)
  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)