Java Parse Date parseDate(String dateString)

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

Description

parse Date

License

Open Source License

Declaration

public static Date parseDate(String dateString) 

Method Source Code

//package com.java2s;
/*// w w w .j  a  va 2s  . c o  m
 * Copyright (c) 2012. The Genome Analysis Centre, Norwich, UK
 * MISO project contacts: Robert Davey @ TGAC
 * *********************************************************************
 *
 * This file is part of MISO.
 *
 * MISO 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 3 of the License, or
 * (at your option) any later version.
 *
 * MISO 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with MISO. If not, see <http://www.gnu.org/licenses/>.
 *
 * *********************************************************************
 */

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

import java.util.Date;

public class Main {
    public static Date parseDate(String dateString) {
        if (isStringEmptyOrNull(dateString)) {
            return null;
        }
        try {
            return getDateFormat().parse(dateString);
        } catch (ParseException e) {
            throw new IllegalArgumentException("Invalid date string");
        }
    }

    public static boolean isStringEmptyOrNull(String s) {
        return "".equals(s) || s == null;
    }

    public static DateFormat getDateFormat() {
        return new SimpleDateFormat("yyyy-MM-dd");
    }
}

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)