Java SQL Date Month getMonthDate(Date myDate, int month)

Here you can find the source of getMonthDate(Date myDate, int month)

Description

Gets the month date.

License

Apache License

Parameter

Parameter Description
myDate the my date
month the month

Return

the month date

Declaration

public static java.sql.Date getMonthDate(Date myDate, int month) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /** The Constant MONTH. */
    public final static String[] MONTH = { "January", "February", "March", "April", "May", "June", "July", "August",
            "September", "October", "November", "December" };

    /**/*from   w  ww.j a va  2  s  .c o  m*/
     * Gets the month date.
     * 
     * @param myDate
     *            the my date
     * @param month
     *            the month
     * @return the month date
     */
    public static java.sql.Date getMonthDate(Date myDate, int month) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(myDate);
        cal.add(Calendar.MONTH, month);
        java.util.Date newDate = cal.getTime();
        return new java.sql.Date(newDate.getTime());
    }

    /**
     * Adds the specified (signed) amount of time to the given time field, based
     * on the calendar's rules.
     * 
     * @param date
     *            the date
     * @param field
     *            the field
     * @param amount
     *            the amount
     * @return the date
     */
    public static Date add(Date date, int field, long amount) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(field, (int) amount);
        return calendar.getTime();
    }
}

Related

  1. getMinDayInMonth(java.sql.Date date)
  2. getMonth(Date date)
  3. getMonth(final java.sql.Date date)
  4. getMonthAmount(java.sql.Date _startDate, java.sql.Date _endDate)
  5. getMonthBefroe(Date date)
  6. getMonthDays(java.sql.Date date)
  7. getMonthFromYMD(Date ymd)
  8. getMonthStart(Date stamp)
  9. getMulmonthday(String startdate, String enddate)