Java Year Format formatYearMonth(Date date)

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

Description

format Year Month

License

Open Source License

Declaration

public static String formatYearMonth(Date date) 

Method Source Code


//package com.java2s;
/*//from  w ww .j  av a 2 s.c om
 * Copyright 2010 Mttang.com All right reserved. This software is the
 * confidential and proprietary information of Mttang.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Mttang.com.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

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

    public static Date formatYearMonth(String day) {
        try {
            return yyyyMM.parse(day);
        } catch (ParseException ex) {
            ex.printStackTrace();
            return new java.util.Date();
        }
    }

    public static String formatYearMonth(Date date) {
        try {
            return yyyyMM.format(date);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
}

Related

  1. formatTimeStampYearFirst(Date date)
  2. formatUniversalMonthYear(Date date)
  3. formatYear(Date d, Locale locale)
  4. formatYear(Date date)
  5. formatYear(Date date)
  6. formatYyyyMm(Date date)
  7. formatyyyyMMddHHmmss(long time)
  8. get_Oracle_DateString_YYYYMMdd_HHmmss(java.util.Date date)
  9. getDDMMYYY_HHMM()