Android Date String Parse parseDate(String date, String pattern, TimeZone zone)

Here you can find the source of parseDate(String date, String pattern, TimeZone zone)

Description

Parses a date using a pattern describing the date and time format.

License

Open Source License

Parameter

Parameter Description
date date in string format
pattern pattern describing the date and time format
zone the given time zone

Exception

Parameter Description
ParseException an exception

Return

a Date parsed from the string

Declaration

public static Date parseDate(String date, String pattern, TimeZone zone)
        throws ParseException 

Method Source Code

//package com.java2s;
/*//from  w  ww  .  j a  v  a2  s  .  co m
 * Copyright (C) 2011-2012 Inaki Ortiz de Landaluce Saiz
 * 
 * This program is free software: you can redistribute it 
 * and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation, either 
 * version 3 of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this program. If not, see 
 * <http://www.gnu.org/licenses/>
 */

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.TimeZone;

public class Main {
    /**
     * Parses a date using a pattern describing the date and time format and the
     * default TimeZone for this host.
     * 
     * @param date
     *            the date in string format
     * @param pattern
     *            the pattern describing the date and time format
     * @return a Date parsed from the string
     * @throws ParseException
     */
    public static Date parseDate(String date, String pattern)
            throws ParseException {
        return parseDate(date, pattern, TimeZone.getDefault());
    }

    /**
     * Parses a date using a pattern describing the date and time format.
     * 
     * @param date
     *            date in string format
     * @param pattern
     *            pattern describing the date and time format
     * @param zone
     *            the given time zone
     * @return a Date parsed from the string
     * @throws ParseException
     */
    public static Date parseDate(String date, String pattern, TimeZone zone)
            throws ParseException {
        DateFormat dfmt = new SimpleDateFormat(pattern);
        dfmt.setTimeZone(zone);
        return dfmt.parse(date);
    }
}

Related

  1. parseDate(String date)
  2. parseDate(String date, SimpleDateFormat sdf)
  3. parseDate(String date, String format)
  4. parseDate(String date, String pattern)
  5. parseDate(String date, String pattern)
  6. parseDate(String dateValue)
  7. parseDate(String dateValue)
  8. parseDate(String dateValue, String[] dateFormats, Date startDate)
  9. parseDate(String dateValue, String[] dateFormats, Date startDate)