Java Year Month calculatorDate(int incrementYear, int incrementMonth, int incrementDay, int incrementHour, int incrementMin, int incrementSec)

Here you can find the source of calculatorDate(int incrementYear, int incrementMonth, int incrementDay, int incrementHour, int incrementMin, int incrementSec)

Description

calculator Date

License

Open Source License

Declaration

public static Date calculatorDate(int incrementYear, int incrementMonth, int incrementDay, int incrementHour,
        int incrementMin, int incrementSec) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {

    public static Date calculatorDate(int incrementYear, int incrementMonth, int incrementDay, int incrementHour,
            int incrementMin, int incrementSec) {
        Calendar c = Calendar.getInstance();

        if (incrementYear != 0) {
            c.add(Calendar.YEAR, incrementYear);
        }//w ww.  ja  v  a 2  s.  c o m
        if (incrementMonth != 0) {
            c.add(Calendar.MONTH, incrementMonth);
        }
        if (incrementDay != 0) {
            c.add(Calendar.DAY_OF_MONTH, incrementDay);
        }
        if (incrementHour != 0) {
            c.add(Calendar.HOUR_OF_DAY, incrementHour);
        }
        if (incrementMin != 0) {
            c.add(Calendar.MINUTE, incrementMin);
        }
        if (incrementSec != 0) {
            c.add(Calendar.SECOND, incrementSec);
        }

        return c.getTime();
    }

    public static Date calculatorDate(Date date, int incrementYear, int incrementMonth, int incrementDay,
            int incrementHour, int incrementMin, int incrementSec) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);

        if (incrementYear != 0) {
            c.add(Calendar.YEAR, incrementYear);
        }
        if (incrementMonth != 0) {
            c.add(Calendar.MONTH, incrementMonth);
        }
        if (incrementDay != 0) {
            c.add(Calendar.DAY_OF_MONTH, incrementDay);
        }
        if (incrementHour != 0) {
            c.add(Calendar.HOUR_OF_DAY, incrementHour);
        }
        if (incrementMin != 0) {
            c.add(Calendar.MINUTE, incrementMin);
        }
        if (incrementSec != 0) {
            c.add(Calendar.SECOND, incrementSec);
        }

        return c.getTime();
    }
}

Related

  1. addDate(Calendar cal, int year, int month, int day)
  2. AddMonths(int yearMonth, int interval)
  3. createCalendar(int year, int month, int date, int hour, int minute, int second)
  4. createDate(final int year, final int month, final int day, final int hour, final int minutes, final int seconds, final int miliseconds)
  5. createDate(int year, int month, int day)
  6. createDate(int year, int month, int dayOfMonth)