Here you can find the source of toDate(final String _text, final String _dateFormat)
Parameter | Description |
---|---|
_text | The string to parse. |
_dateForamt | A format like <code>yyyy-MM-dd HH24:MI:ss</code> |
public static Date toDate(final String _text, final String _dateFormat)
//package com.java2s; /*/*from w ww .j a v a 2s .co m*/ * $Id$ * ============================================================================ * Project grooocle * Copyright (c) 2008-2010 by Andre Winkler. All rights reserved. * ============================================================================ * GNU LESSER GENERAL PUBLIC LICENSE * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; /** * Convert a string into a date type. Throws a runtime exception if string * is unparseable. * * @param _text * The string to parse. * * @return The date object. */ public static Date toDate(final String _text) { return (toDate(_text, DATE_FORMAT)); } /** * Convert a string into a date type. Throws a runtime exception if string * is not to parse. * * @param _text * The string to parse. * * @param _dateForamt * A format like <code>yyyy-MM-dd HH24:MI:ss</code> * * @return The date object. */ public static Date toDate(final String _text, final String _dateFormat) { SimpleDateFormat formatter = new SimpleDateFormat(_dateFormat); try { return formatter.parse(_text); } catch (ParseException ex) { throw new RuntimeException(ex); } } }