Java Parse Date parseDate(String t)

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

Description

Parse a date string

License

Open Source License

Declaration

static public Date parseDate(String t) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w .  ja  v  a  2 s.  c o m*/
 * IRIS -- Intelligent Roadway Information System
 * Copyright (C) 2009-2014  Minnesota Department of Transportation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

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

import java.util.Date;

public class Main {
    /** Date parser formats */
    static private final DateFormat[] DATE_FORMATS = {
            new SimpleDateFormat("MM/dd/yy"),
            new SimpleDateFormat("MM/dd/yyyy"),
            new SimpleDateFormat("yyyy-MM-dd"), };

    /** Parse a date string */
    static public Date parseDate(String t) {
        for (DateFormat df : DATE_FORMATS) {
            try {
                return df.parse(t);
            } catch (ParseException e) {
                // Ignore
            }
        }
        return null;
    }
}

Related

  1. parseDate(String strDate)
  2. parseDate(String strDate, String format)
  3. parseDate(String strFormat, String dateValue)
  4. parseDate(String string)
  5. ParseDate(String string, String format)
  6. parseDate(String text)
  7. parseDate(String text, String[] datePattern, int index)
  8. parseDate(String time)
  9. parseDate(String time)