Here you can find the source of getCalendar(String dateString, String format, TimeZone tz)
public static Calendar getCalendar(String dateString, String format, TimeZone tz) throws Exception
//package com.java2s; /*// w w w . j a v a 2 s . com * This software is distributed under the terms of the FSF * Gnu Lesser General Public License (see lgpl.txt). * * This program is distributed WITHOUT ANY WARRANTY. See the * GNU General Public License for more details. */ import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { public static Calendar getCalendar(String dateString, String format, TimeZone tz) throws Exception { if (dateString == null || format == null || dateString.equals("") || tz == null) return null; Calendar cal = null; try { Date date = getDate(dateString, format, tz); cal = Calendar.getInstance(); cal.setTime(date); } catch (Exception ex) { throw new Exception("Error parsing date " + dateString + " with this format " + format); } return cal; } public static Calendar getCalendar(String dateString, String format) throws Exception { if (dateString == null || format == null || dateString.equals("")) return null; Calendar cal = null; try { Date date = getDate(dateString, format); cal = Calendar.getInstance(); cal.setTime(date); } catch (Exception ex) { throw new Exception("Error parsing date " + dateString + " with this format " + format); } return cal; } public static Date getDate(String dateString, String format, TimeZone tz) throws Exception { if (dateString == null || format == null || dateString.equals("") || tz == null) return null; SimpleDateFormat formatter = new SimpleDateFormat(format); formatter.setTimeZone(tz); ParsePosition pos = new ParsePosition(0); return formatter.parse(dateString, pos); } public static Date getDate(String dateString, String format) throws Exception { return getDate(dateString, format, TimeZone.getDefault()); } }