Java Month Get getMonthString(Date date)

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

Description

get Month String

License

Open Source License

Declaration

public static String getMonthString(Date date) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public final static String monthFormat = "yyyyMM";

    public static String getMonthString(Date date) {
        DateFormat dateFormat = createNewDateFormat(monthFormat);
        return formatDateString(date, dateFormat);
    }//w  w w .j a v  a  2 s. c  o m

    public static DateFormat createNewDateFormat(String pattern) {
        DateFormat df = new SimpleDateFormat(pattern);
        df.setLenient(false);
        return df;
    }

    public static String formatDateString(Date date, DateFormat dateFormat) {
        if (date == null || dateFormat == null) {
            return null;
        }
        return dateFormat.format(date);
    }

    public static String format(Date date, String format) {
        if (date == null) {
            return null;
        }
        return new SimpleDateFormat(format).format(date);
    }
}

Related

  1. getMonthRange(String strBeginDate, String strEndDate, String pattern)
  2. getMonths()
  3. getMonths(DateFormatSymbols symbols)
  4. getMonthSpace(Date date)
  5. getMonthStartTime(int year, int month)
  6. getMonthString(int month)
  7. getMonthStringFromNumber(String monthNumber)
  8. getMonthStrings()
  9. getNearbyMonth(String month, int i)