Java Parse Date Pattern YYYY parse(String date)

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

Description

Returns a Date object instance from the input string.

License

Open Source License

Parameter

Parameter Description
date The date string.

Exception

Parameter Description

Return

The date instance created.

Declaration

public static Date parse(String date) throws java.text.ParseException 

Method Source Code

//package com.java2s;
/*/*from w ww  . j  a  v a2 s.  c o  m*/
 * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
 * Institute of Systems Science, National University of Singapore
 *
 * Copyright 2012 Team 4(Part-Time), ISS, NUS, Singapore. All rights reserved.
 * Use of this source code is subjected to the terms of the applicable license
 * agreement.
 *
 * -----------------------------------------------------------------
 * REVISION HISTORY
 * -----------------------------------------------------------------
 * DATE             AUTHOR          REVISION      DESCRIPTION
 * 10 March 2012    Chen Changfeng   0.1            Class creating
 *                                        
 *                                        
 *                                        
 *                                        
 * 
 */

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    private static String dateFormat = "dd/MM/yyyy";

    /**
     * Returns a Date object instance from the input string.
     * The input string is parsed to return a date object based
     * on the date format specified in the System property.
     * <p>
     * @param  date The date string.
     * @return The date instance created.
     * @throws java.text.ParseException  - if the beginning of the specified string cannot be parsed.
     */
    public static Date parse(String date) throws java.text.ParseException {
        // Modified by Aris on 02/02/2009 for case 1296351
        //if ( date == null || date.length()==0) return null;
        if (date == null)
            return null;

        String dateformat = null;
        // Use the default format of "dd/MM/yyyy".
        dateformat = dateFormat;

        return parse(date, dateformat);
    }

    /**
     * Returns a Date object instance from the input string.
     * The input date string is parsed to return a date object
     * based on the format provided.
     * <p>
     * Eg., to parse the date string "01/01/2003 9:2 PM", use the
     * format "dd/MM/yyyy h:m a". The resultant data object will have
     * the value "Mar 11 2003 09:02", as displayed in 24 hr format.
     * <p>
     * @param  date   The date string.
     * @param  format The date format that the date string conforms to.
     * @return The date instance created.
     * @throws java.text.ParseException  - if the beginning of the specified string cannot be parsed.
     */
    public static Date parse(String date, String format)
            throws java.text.ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        sdf.setLenient(false);

        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)