Here you can find the source of parseDate(String date, String pattern, TimeZone zone)
Parameter | Description |
---|---|
date | date in string format |
pattern | pattern describing the date and time format |
zone | the given time zone |
Parameter | Description |
---|---|
ParseException | an exception |
public static Date parseDate(String date, String pattern, TimeZone zone) throws ParseException
//package com.java2s; /*//from www . j a va 2s .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); } }