Here you can find the source of parseDate(String dateString, String format, TimeZone zone)
Parameter | Description |
---|---|
dateString | The date of the string types |
format | format pattern |
zone | timeZone |
public static Date parseDate(String dateString, String format, TimeZone zone)
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { /**// ww w. j ava 2s . com * Transferred in accordance with the specified format string date into a Date type. * * <pre> * <code> * DateUtils.parseDate(20120202, "yyyyMMdd", TimeZone.getDefault()) = 20120202; * </code> * </pre> * * @param dateString The date of the string types * @param format format pattern * @param zone timeZone * @return Date */ public static Date parseDate(String dateString, String format, TimeZone zone) { Date date = null; try { DateFormat df = getDateFormat(format); df.setTimeZone(zone); date = df.parse(dateString); } catch (Exception e) { return null; } return date; } /** * According to the specified format, String type Date object to parse the return value is a * Date object. * * <pre> * <code> * DataUtils.parseDate("2012-12-01", "yyyy-MM-dd") = 2012-12-01 * </code> * </pre> * * @param dateString dateValue of string type * @param pattern formate pattern * @return Date */ public static Date parseDate(String dateString, String pattern) { Date result = null; DateFormat sdf = getDateFormat(pattern); sdf.setLenient(false); try { result = sdf.parse(dateString); } catch (Exception e) { result = null; } return result; } /** * return date format with Locale US. * * @param pattern date format pattern. * @return DateFormat */ public static DateFormat getDateFormat(String pattern) { return new SimpleDateFormat(pattern, Locale.US); } }