Java Month Format formatMonth(Date date)

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

Description

format Month

License

Open Source License

Return

Localized date value in format yyyy-MM

Declaration

public static String formatMonth(Date date) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

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

public class Main {
    private static SimpleDateFormat monthDF = // getDateShortFormat
            new SimpleDateFormat("yyyy / MM", Locale.getDefault());
    private static String NOT_DEFINED_DATE = "-";

    /**/*from   ww w .  j av a 2s  . c o  m*/
     * @return Localized date value in format yyyy-MM
     */
    public static String formatMonth(Date date) {
        if (date == null) {
            return NOT_DEFINED_DATE;
        }
        return monthDF.format(date.getTime());
    }

    public static String getTime(Date time, int format, Locale locale) {
        return SimpleDateFormat.getTimeInstance(format, locale).format(time);
    }
}

Related

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