Java Month Get getMonthSpace(Date date)

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

Description

get Month Space

License

Open Source License

Declaration

public static int getMonthSpace(Date date) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String YYYYMMDDHHMMSS = "yyyy-MM-dd HH:mm:ss";

    public static int getMonthSpace(Date date) {

        SimpleDateFormat df = new SimpleDateFormat(YYYYMMDDHHMMSS);
        String sysTime = df.format(new Date());
        String creTime = df.format(date);
        ;/*from w  ww.  jav  a 2s  .c  o m*/
        int inum = 0;
        int sysYear = Integer.parseInt(sysTime.substring(0, 4));
        int sysMonth = Integer.parseInt(sysTime.substring(5, 7));
        int creYear = Integer.parseInt(creTime.substring(0, 4));
        int creMonth = Integer.parseInt(creTime.substring(5, 7));

        if (sysYear == creYear) {
            inum = sysMonth - creMonth;
        } else {
            inum = (sysYear * 12 + sysMonth) - (creYear * 12 + creMonth);
        }
        return Math.abs(inum);
    }
}

Related

  1. getMonthOfSeason(Date date, boolean firstOrLast)
  2. getMonthPath(Date date)
  3. getMonthRange(String strBeginDate, String strEndDate, String pattern)
  4. getMonths()
  5. getMonths(DateFormatSymbols symbols)
  6. getMonthStartTime(int year, int month)
  7. getMonthString(Date date)
  8. getMonthString(int month)
  9. getMonthStringFromNumber(String monthNumber)