Java Month Convert createFutureDate(int days, int months)

Here you can find the source of createFutureDate(int days, int months)

Description

Creates a new date/time string presented in the SIP2 format "yyyyMMdd HHmmss" by adding the given number of days and months to the current date.

License

Open Source License

Parameter

Parameter Description
days number of days to be added to the current date
months number of months to be added to the current date

Return

current date plus the given number of days and months in the SIP2 format "yyyyMMdd HHmmss"

Declaration

public static String createFutureDate(int days, int months) 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/*from  w  w w .ja v  a  2  s  .  co  m*/
     * Creates a new date/time string presented in the SIP2 format
     * "yyyyMMdd    HHmmss" by adding the given number of days and months
     * to the current date. This method is usefull when setting an
     * expiration date to a hold.
     *
     * @param days   number of days to be added to the current date
     * @param months number of months to be added to the current date
     * @return current date plus the given number of days and months in the
     * SIP2 format "yyyyMMdd    HHmmss"
     */
    public static String createFutureDate(int days, int months) {
        Calendar date = Calendar.getInstance();
        date.setTime(new Date());
        date.add(Calendar.DATE, days);
        date.add(Calendar.MONTH, months);
        return toSipDateTime(date.getTime());
    }

    /**
     * Converts the given date to a SIP2 formatted date/time string. The SIP2
     * format is "yyyyMMdd    HHmmss".
     *
     * @param date date object to be converted
     * @return SIP2 formatted date/time string
     */
    public static String toSipDateTime(Date date) {
        SimpleDateFormat simpleDf = new SimpleDateFormat("yyyyMMdd    HHmmss");
        return simpleDf.format(date);
    }
}

Related

  1. convertMonthStringToInt(String monthString)
  2. ConvertNumToMonth(int mesEntrada)
  3. convertToAlphaMonth(final int importIntMonth)
  4. convertToMonth_long(int month)
  5. convertToNumericMonth(String importStrMonth)
  6. differenceMonth(String strDate1, String strDate2)
  7. isCurMonth(String month)
  8. month()
  9. month(Date date, Locale locale)