Here you can find the source of parse(String date, String format)
Parameter | Description |
---|---|
date | The date string. |
format | The date format that the date string conforms to. |
Parameter | Description |
---|
public static Date parse(String date, String format) throws java.text.ParseException
//package com.java2s; /**//from w w w. j a v a2 s .c om * Copyright 2012 NCS Pte. Ltd. All Rights Reserved * * This software is confidential and proprietary to NCS Pte. Ltd. You shall * use this software only in accordance with the terms of the license * agreement you entered into with NCS. No aspect or part or all of this * software may be reproduced, modified or disclosed without full and * direct written authorisation from NCS. * * NCS SUPPLIES THIS SOFTWARE ON AN "AS IS" BASIS. NCS MAKES NO * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESSLY OR IMPLIEDLY, ABOUT THE * SUITABILITY OR NON-INFRINGEMENT OF THE SOFTWARE. NCS SHALL NOT BE LIABLE * FOR ANY LOSSES OR DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ import java.text.SimpleDateFormat; import java.util.Date; public class Main { /** * 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); // TimeZone tz = TimeZone.getTimeZone( timezone ); // sdf.setTimeZone(tz); return sdf.parse(date); } }