Here you can find the source of getMonthDate(Date myDate, int month)
Parameter | Description |
---|---|
myDate | the my date |
month | the month |
public static java.sql.Date getMonthDate(Date myDate, int month)
//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(); } }