Java Parse Date parseDate(String myDate, String pattern)

Here you can find the source of parseDate(String myDate, String pattern)

Description

Parses a string into a date.

License

Open Source License

Parameter

Parameter Description
myDate The date string.
pattern The pattern to use. <p>

Exception

Parameter Description
ParseException an exception

Return

The Date.

Declaration

public static java.util.Date parseDate(String myDate, String pattern) throws ParseException 

Method Source Code


//package com.java2s;
/*/*  w ww  .ja va  2s . c om*/
 * DateHelper.java
 *
 * Copyright (c) 2004-2011 Gregory Kotsaftis
 * gregkotsaftis@yahoo.com
 * http://zeus-jscl.sourceforge.net/
 *
 * 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;

public class Main {
    /**
     * Parses a string into a date. String should be in
     * <code>SimpleDateFormat</code> format. e.g.
     * <code>java.util.Date d = parseDate(myDate, "dd/MM/yyyy");</code>
     * <p>
     * 
     * @param myDate
     *            The date string.
     * @param pattern
     *            The pattern to use.
     *            <p>
     * @return The <code>Date</code>.
     *         <p>
     * @throws ParseException
     */
    public static java.util.Date parseDate(String myDate, String pattern) throws ParseException {
        if (myDate == null || pattern == null)
            throw new ParseException("Null arguments!", 0);

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        java.util.Date uDate = simpleDateFormat.parse(myDate);
        return (uDate);
    }
}

Related

  1. parseDate(String formattedDate)
  2. parseDate(String gameDate)
  3. parseDate(String in)
  4. parseDate(String input)
  5. parseDate(String line)
  6. parseDate(String partten, String datatime)
  7. parseDate(String representedValue)
  8. parseDate(String s)
  9. parseDate(String s)