Java TimeZone Add stringToCalendar(String strDate, TimeZone timezone)

Here you can find the source of stringToCalendar(String strDate, TimeZone timezone)

Description

String to calendar.

License

Open Source License

Parameter

Parameter Description
strDate the str date
timezone the timezone

Exception

Parameter Description
ParseException the parse exception

Return

the calendar

Declaration

public static Calendar stringToCalendar(String strDate, TimeZone timezone) throws ParseException 

Method Source Code


//package com.java2s;
/*/*ww  w. j ava  2 s.co  m*/
 * DateUtil.java
 * Copyright (c) 2014, EcoFactor, All Rights Reserved.
 *
 * This software is the confidential and proprietary information of EcoFactor
 * ("Confidential Information"). You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you entered into with
 * EcoFactor.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import java.util.Locale;

import java.util.TimeZone;

public class Main {
    /**
     * String to calendar.
     * @param strDate the str date
     * @param timezone the timezone
     * @return the calendar
     * @throws ParseException the parse exception
     */
    public static Calendar stringToCalendar(String strDate, TimeZone timezone) throws ParseException {

        String FORMAT_DATETIME = "yyyy-MM-dd'T'HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATETIME, Locale.ENGLISH);
        sdf.setTimeZone(timezone);
        Date date = sdf.parse(strDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal;
    }
}

Related

  1. millisFromEpochToHourId(long millis, TimeZone tz)
  2. nowWithTimeZone(TimeZone timezone)
  3. removeTimeZoneOffset(long t)
  4. shiftDate(Date date, TimeZone timeZone, String pattern)
  5. stringToCal(String s, TimeZone tz)
  6. toMidnight(long time, TimeZone tz)
  7. tomorrow(TimeZone zone)