Java SQL Time parseCalendar(final TimeZone timezone, final Locale locale, final String dateformat, final String datestring)

Here you can find the source of parseCalendar(final TimeZone timezone, final Locale locale, final String dateformat, final String datestring)

Description

Parse a Date string into a Calendar according to the specified Date format, for the specified TimeZone and Locale.

License

Open Source License

Parameter

Parameter Description
timezone a parameter
locale a parameter
dateformat a parameter
datestring a parameter

Exception

Parameter Description
ParseException an exception

Return

Calendar

Declaration


public static Calendar parseCalendar(final TimeZone timezone,
        final Locale locale, final String dateformat,
        final String datestring) throws ParseException 

Method Source Code

//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);
    }
}

Related

  1. mergeDateTime(Date date, Time time)
  2. minTime()
  3. minutesToTime(int minutes)
  4. parse(String dateTimeString)
  5. parseAMPMFormat(String datetimeString)
  6. parseDate(String datetime, String format)
  7. readTime(ByteBuffer buffer)
  8. removeTimefromDate(Date inputDate)
  9. resetDayTime(Time date)