Here you can find the source of str2Calendar(String str, String format)
public static Calendar str2Calendar(String str, String format)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { private static final String FORMAT = "yyyy-MM-dd HH:mm:ss"; public static Calendar str2Calendar(String str) { return str2Calendar(str, null); }/* w w w. j a v a 2 s. c om*/ public static Calendar str2Calendar(String str, String format) { Date date = str2Date(str, format); if (date == null) { return null; } Calendar c = Calendar.getInstance(); c.setTime(date); return c; } public static Date str2Date(String str) { return str2Date(str, null); } public static Date str2Date(String str, String format) { if (str == null || str.length() == 0) { return null; } if (format == null || format.length() == 0) { format = FORMAT; } Date date = null; try { SimpleDateFormat sdf = new SimpleDateFormat(format); date = sdf.parse(str); } catch (Exception e) { e.printStackTrace(); } return date; } }