Java Month Format formatMonth(final Date date)

Here you can find the source of formatMonth(final Date date)

Description

Format the Date using pattern "yyyy-MM"

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static String formatMonth(final Date date) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final SimpleDateFormat monthFormat = new SimpleDateFormat("yyyy-MM");

    /**// ww w  .j  a  v a 2  s  .c o m
     * Format the Date using pattern "yyyy-MM"
     *
     * @param date
     * @return
     */
    public static String formatMonth(final Date date) {
        return formatMonth(date, null);
    }

    public static String formatMonth(final Date date, final String defaultValue) {
        if (date == null) {
            return defaultValue;
        }
        return monthFormat.format(date);
    }
}

Related

  1. addMonths(String src, int addMonth, String format)
  2. formatMonth(Date date)
  3. formatMonth(Date date)
  4. formatMonth(final int year, final int month)
  5. formatMonth(int month)
  6. formatMonth(int month, Locale locale, boolean longFormat)
  7. formatMonth(String dateOrign)