Here you can find the source of stringToCalendar(String timeStr)
public static Calendar stringToCalendar(String timeStr)
//package com.java2s; /**/*from www . j av a 2 s . co m*/ * Program : CommonsFiend.java * Author : niehai * Create : 2008-5-14 ????05:05:54 * * Copyright 2007 by Embedded Internet Solutions Inc., * All rights reserved. * * This software is the confidential and proprietary information * of Embedded Internet Solutions Inc.("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 Embedded Internet Solutions Inc. * */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Calendar stringToCalendar(String timeStr) { Date date = stringToTime(timeStr); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar; } public static Date stringToTime(String timeStr) { Date date = new Date(); SimpleDateFormat apf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { date = apf.parse(timeStr); } catch (ParseException e) { e.printStackTrace(); } return date; } public static Date stringToTime(String timeStr, String formatString) { Date date = new Date(); SimpleDateFormat apf = new SimpleDateFormat(formatString); try { date = apf.parse(timeStr); } catch (ParseException e) { e.printStackTrace(); } return date; } }