Here you can find the source of addDate(String dt, long day)
public static java.util.Date addDate(String dt, long day)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { private final static int MILLIS_PER_HOUR = 3600000; public static java.util.Date addDate(String dt, long day) { if (dt == null) { throw new IllegalArgumentException("dt can not be null"); }/*w w w .j a va 2 s . co m*/ int len = dt.length(); if (!(len == 8 || len == 14)) { throw new IllegalArgumentException("dt length must be 8 or 14 (yyyyMMdd or yyyyMMddHHmmss)"); } if (len == 8) { dt += "090000"; } return addDate(getDate(dt), day); } public static java.util.Date addDate(java.util.Date dt, long day) { return new java.util.Date(dt.getTime() + (MILLIS_PER_HOUR * 24L * day)); } /** * yyyyMMddHHmmss --> java.util.Date * @param String dt * @return java.util.Date */ private static java.util.Date getDate(String dt) { Calendar cal = Calendar.getInstance(); cal.set(Integer.valueOf(dt.substring(0, 4)).intValue(), Integer.valueOf(dt.substring(4, 6)).intValue() - 1, Integer.valueOf(dt.substring(6, 8)).intValue(), Integer.valueOf(dt.substring(8, 10)).intValue(), Integer.valueOf(dt.substring(10, 12)).intValue(), Integer.valueOf(dt.substring(12, 14)).intValue()); return cal.getTime(); } }