Here you can find the source of DateAdd(String strDate, int iCount, int iType)
public static String DateAdd(String strDate, int iCount, int iType)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static String DateAdd(String strDate, int iCount, int iType) { Calendar Cal = parseDateTime(strDate); int pType = 0; if (iType == 0) { pType = 1;// w w w. j a v a 2 s . c om } else if (iType == 1) { pType = 2; } else if (iType == 2) { pType = 5; } else if (iType == 3) { pType = 10; } else if (iType == 4) { pType = 12; } else if (iType == 5) { pType = 13; } Cal.add(pType, iCount); SimpleDateFormat sdf = null; if (iType <= 2) sdf = new SimpleDateFormat("yyyy-MM-dd"); else sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sDate = sdf.format(Cal.getTime()); return sDate; } public static String DateAdd(String strOption, int iDays, String strStartDate) { if (!strOption.equals("d")) ; return strStartDate; } public static Calendar parseDateTime(String baseDate) { Calendar cal = null; cal = new GregorianCalendar(); int yy = Integer.parseInt(baseDate.substring(0, 4)); int mm = Integer.parseInt(baseDate.substring(5, 7)) - 1; int dd = Integer.parseInt(baseDate.substring(8, 10)); int hh = 0; int mi = 0; int ss = 0; if (baseDate.length() > 12) { hh = Integer.parseInt(baseDate.substring(11, 13)); mi = Integer.parseInt(baseDate.substring(14, 16)); ss = Integer.parseInt(baseDate.substring(17, 19)); } cal.set(yy, mm, dd, hh, mi, ss); return cal; } public static String getTime() { Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(currentTime); String min; min = dateString.substring(14, 16); return min; } }