Java Day in Month GetDay(int month)

Here you can find the source of GetDay(int month)

Description

Get Day

License

Open Source License

Declaration

public static String GetDay(int month) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**//from  w ww. jav a  2 s  .c  om
     * 
     * @param strFormat
     * @param iDays
     * @return update 2012-9-7
     */
    public static String GetDay(String strFormat, int iDays) {
        Date cDate = new Date();
        cDate = AddDate(cDate, iDays);
        SimpleDateFormat cSimpleDateFormat = new SimpleDateFormat(strFormat);
        return cSimpleDateFormat.format(cDate);
    }

    public static String GetDay(int month) {
        java.util.Calendar cal = java.util.Calendar.getInstance();
        java.text.SimpleDateFormat sDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd");
        cal.add(Calendar.MONTH, month);
        sDateFormat.format(cal.getTime());
        System.out.println(sDateFormat.format(cal.getTime()));
        return sDateFormat.format(cal.getTime());
    }

    /**
     * 
     * @param date
     *            Date
     * @param days
     *            int
     * @return Date
     */
    public static Date AddDate(Date date, int days) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        long lTmp = c.getTimeInMillis();
        c.setTimeInMillis(lTmp + ((long) days) * 24 * 3600 * 1000);
        return c.getTime();
    }
}

Related

  1. firstDayOfLastMonth()
  2. firstDayOfMonth(int commonMonthIndx, int iyear)
  3. firstDayOfMonth(int year, int month, String dateFormat)
  4. firstDayOfNextMonth(String dateFormat)
  5. getCountDayForMonth(int year, int month)
  6. getDayByOfSomeMonth(String curday, int month)
  7. getDayMonth(String dayofmonth)
  8. getDayOfMonth(Date d)
  9. getDayOfMonth(Date date)