Java Date to Month getMonthName(Date date)

Here you can find the source of getMonthName(Date date)

Description

get Month Name

License

Open Source License

Declaration

public static String getMonthName(Date date) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static String getMonthName(Date date) {
        Calendar temp = Calendar.getInstance();
        temp.setTime(date);//  w w w.  j a  v  a2 s  .c  om

        int y = temp.get(Calendar.YEAR);
        int m = temp.get(Calendar.MONTH) + 1;
        int d = temp.get(Calendar.DAY_OF_MONTH);

        int rm = 0, ry = 0;

        if (d >= 1 && d <= 20) {
            rm = m;
            ry = y;
        }
        if (d >= 21) {
            if (m == 12) {
                ry = y + 1;
                rm = 1;
            } else {
                rm = m + 1;
                ry = y;
            }
        }
        String result_str = String.valueOf(ry) + "-" + String.valueOf(rm);
        return result_str;
    }
}

Related

  1. getMonthFromDate(Date date)
  2. getMonthInterval(Date _one, Date _two)
  3. getMonthLastDate(Date date)
  4. getMonthLastDay(Date date)
  5. getMonthlyKey(Date d)
  6. getMonthOfCurrentTime(Date date)
  7. getMonthOffset(Date sourceDate, Date targetDate)
  8. getMonthOfThisYear(Date currentdate)
  9. getMonthOfYear(Date date)