Java Year Parse parseYYYYMMDD(String yyyymmdd)

Here you can find the source of parseYYYYMMDD(String yyyymmdd)

Description

Parse a String in yyyy-MM-dd format to a date.

License

Open Source License

Parameter

Parameter Description
yyyymmdd the String to parse.

Return

the date represented by the string, or null if the string could not be parsed.

Declaration

public static Date parseYYYYMMDD(String yyyymmdd) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w.ja  va2s  . c  o  m*/
 * SuprSetr is Copyright 2010-2014 by Jeremy Brooks
 *
 * This file is part of SuprSetr.
 *
 * SuprSetr 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.
 *
 * SuprSetr 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 SuprSetr.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**
     * Date formatter for a yyyy-MM-dd format.
     */
    private static SimpleDateFormat yyyyMMddFormatter = new SimpleDateFormat(
            "yyyy-MM-dd");

    /**
     * Parse a String in yyyy-MM-dd format to a date.
     *
     * @param yyyymmdd the String to parse.
     * @return the date represented by the string, or null if the string could
     *         not be parsed.
     */
    public static Date parseYYYYMMDD(String yyyymmdd) {
        Date retDate = null;

        try {
            retDate = yyyyMMddFormatter.parse(yyyymmdd);
        } catch (Exception e) {
            // no biggie, will return null
        }

        return retDate;
    }
}

Related

  1. parseddMMyyyy(String dateStr)
  2. parseDdMmYyyyDate(String date)
  3. parseTimeByYYYYMMDDHHMMSS(String str)
  4. parseYYYYMMDD(String s)
  5. parseYYYYMMDD(String yyyyDashmmDashdd)
  6. parseYYYYMMDD(String yyyymmdd)