Here you can find the source of addDate(Calendar cal, int year, int month, int day)
public static Date addDate(Calendar cal, int year, int month, int day)
//package com.java2s; import java.util.*; public class Main { public static Date addDate(Calendar cal, int year, int month, int day) { int y = cal.get(Calendar.YEAR); int m = cal.get(Calendar.MONTH); int d = cal.get(Calendar.DATE); cal.set(y + year, m + month, d + day); return cal.getTime(); }/*ww w .java 2 s . c om*/ public static Date getTime(String hhmm) { if (hhmm != null && hhmm.length() == 4 && isDigit(hhmm)) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hhmm.substring(0, 2))); cal.set(Calendar.MINUTE, Integer.parseInt(hhmm.substring(2, 4))); return cal.getTime(); } return null; } private static boolean isDigit(String digitStr) { if (digitStr != null) { for (int i = 0; i < digitStr.length(); i++) if (!Character.isDigit(digitStr.charAt(i))) return false; } return true; } }