Java Day daysFrom(Date date, int amount, String format)

Here you can find the source of daysFrom(Date date, int amount, String format)

Description

days From

License

Open Source License

Declaration

public static String daysFrom(Date date, int amount, String format) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Oobium, Inc.//from  ww  w . j  a v  a  2s. com
 * 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:
 *     Jeremy Dowdall <jeremy@oobium.com> - initial API and implementation
 ******************************************************************************/

import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static Date daysFrom(Date date, int amount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DATE, amount);
        return cal.getTime();
    }

    public static String daysFrom(Date date, int amount, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(daysFrom(date, amount));
    }

    private static Date add(Date date, int field, int amount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(field, amount);
        return cal.getTime();
    }
}

Related

  1. dayFilter(Date date)
  2. dayForAMorPM(String date)
  3. dayFormat(Date date)
  4. dayOfDate(Date s)
  5. dayOfWeekAbr(Date date)
  6. daysOfnumbe(Date sDate, int number)
  7. daySub(Date fDate, Date oDate)
  8. daysWeekName(boolean shortName, Locale locale)
  9. dayToMilliSeconds(String day, String timeZone)