Here you can find the source of parse(String date)
Parameter | Description |
---|---|
date | The date string. |
Parameter | Description |
---|
public static Date parse(String date) throws java.text.ParseException
//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); } }