Here you can find the source of addDays(Date d, double count)
public static Date addDays(Date d, double count)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w. j a va 2 s. c om*/ * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ import java.util.Calendar; import java.util.Date; public class Main { /** * add count days days is truncated to second and can be negative */ public static Date addDays(Date d, double count) { if (d == null) { return null; } int sec = (int) (count * 3600 * 24); int sign = 1; if (sec < 0) { sec = -sec; sign = -1; } Calendar cal = Calendar.getInstance(); cal.setTime(d); cal.add(Calendar.DATE, sign * (sec / 3600 / 24)); cal.add(Calendar.HOUR_OF_DAY, sign * ((sec / 3600) % 24)); cal.add(Calendar.MINUTE, sign * ((sec / 60) % 60)); cal.add(Calendar.SECOND, sign * (sec % 60)); return cal.getTime(); } }