Here you can find the source of stringToCalendar(String strDate, TimeZone timezone)
Parameter | Description |
---|---|
strDate | the str date |
timezone | the timezone |
Parameter | Description |
---|---|
ParseException | the parse exception |
public static Calendar stringToCalendar(String strDate, TimeZone timezone) throws ParseException
//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; } }