Here you can find the source of parseCalendar(final TimeZone timezone, final Locale locale, final String dateformat, final String datestring)
Parameter | Description |
---|---|
timezone | a parameter |
locale | a parameter |
dateformat | a parameter |
datestring | a parameter |
Parameter | Description |
---|---|
ParseException | an exception |
public static Calendar parseCalendar(final TimeZone timezone, final Locale locale, final String dateformat, final String datestring) throws ParseException
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; public class Main { /*********************************************************************************************** * Parse a Date string into a Calendar according to the specified Date format, * for the specified TimeZone and Locale. */*w w w.ja v a2 s .c om*/ * @param timezone * @param locale * @param dateformat * @param datestring * * @return Calendar * * @throws ParseException */ public static Calendar parseCalendar(final TimeZone timezone, final Locale locale, final String dateformat, final String datestring) throws ParseException { final SimpleDateFormat dateFormat; final GregorianCalendar calendar; final java.sql.Date date; // ToDo Consider ThreadLocal dateFormat = new SimpleDateFormat(dateformat, locale); dateFormat.setTimeZone(timezone); date = new java.sql.Date(dateFormat.parse(datestring).getTime()); // Take the Date via a calendar to avoid any incomprehensible changes... calendar = new GregorianCalendar(timezone, locale); calendar.setTimeInMillis(date.getTime()); return (calendar); } }