Java Parse Date Pattern YYYY parse(String date)

Here you can find the source of parse(String date)

Description

Method for parsing a String into a date with default format (dd/MM/yyyy)

License

Open Source License

Parameter

Parameter Description
date String to be parsed

Exception

Parameter Description
ParseException inherited from SimpleDateFormat.parse(String)

Return

resultant Date Object

Declaration

public static Date parse(String date) throws ParseException 

Method Source Code

//package com.java2s;
/*//from  www.j a va2  s .co  m
Copyright 2012 Juan Mart?n Runge
    
jmrunge@gmail.com
http://www.zirsi.com.ar
    
This file is part of ZirUtils.
    
ZirUtils 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.
    
ZirUtils 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 ZirUtils.  If not, see <http://www.gnu.org/licenses/>.
*/

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

import java.util.Date;

public class Main {
    /**
     * Method for parsing a String into a date with default format (dd/MM/yyyy)
     * 
     * @param date String to be parsed
     * @return resultant Date Object
     * @throws ParseException inherited from SimpleDateFormat.parse(String)
     * @see java.text.SimpleDateFormat
     */
    public static Date parse(String date) throws ParseException {
        return parse(date, null);
    }

    /**
     * Method for parsing a String into a Date with specified format
     * 
     * @param date String to be parsed
     * @param format the format
     * @return resultant Date Object
     * @throws ParseException inherited from SimpleDateFormat.parse(String)
     * @see java.text.SimpleDateFormat
     */
    public static Date parse(String date, String format) throws ParseException {
        if (date == null)
            return null;
        if (format == null)
            format = "dd/MM/yyyy";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.parse(date);
    }
}

Related

  1. parse(String date)
  2. parse(String date)
  3. parse(String date)
  4. parse(String date)
  5. parse(String date)
  6. parse(String date)
  7. parse(String date)
  8. parse(String date)
  9. parse(String date, String format)