Java Month Format getLastYearMonthYYYYMM()

Here you can find the source of getLastYearMonthYYYYMM()

Description

get Last Year Month YYYYMM

License

Open Source License

Declaration

public static String getLastYearMonthYYYYMM() 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {

    public static String getLastYearMonthYYYYMM() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
        SimpleDateFormat simpleFormate = new SimpleDateFormat("yyyyMM");
        return simpleFormate.format(calendar.getTime()).trim();
    }/*  w  ww.  j  av  a2s.co m*/

    public static String format(java.util.Date date, String format) {
        String result = "";
        try {
            if (date != null) {
                java.text.DateFormat df = new java.text.SimpleDateFormat(format);
                result = df.format(date);
            }
        } catch (Exception e) {
        }
        return result;
    }

    public static String format(java.util.Date date) {
        return format(date, "yyyy/MM/dd");
    }

    public static String getTime(java.util.Date date) {
        return format(date, "HH:mm:ss");
    }
}

Related

  1. getAfterByNMonth(String format, int months)
  2. getCurrMonthFirstDaySlashFormat()
  3. getDisplayMonth(Date time, int monthBefore, int monthAfter, SimpleDateFormat format)
  4. getFirstDayOfNextMonth(String dateFormat)
  5. getFormatCurMonthAsYYYYMM()
  6. getMonthFormat(String dateString)
  7. getUpMonthDate(String date, String dateFormat)
  8. getYesterMonthDate(String format)
  9. monthsBetween(String from, String to, String format)