Here you can find the source of getMonthSpace(Date date)
public static int getMonthSpace(Date date)
//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); } }