Java Date to Year getYearMonthInt(Date date)

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

Description

get Year Month Int

License

Open Source License

Declaration

public static Integer getYearMonthInt(Date date) 

Method Source Code

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

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {

    public static Integer getYearMonthInt(Date date) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);/*  w ww.j  a v  a2s  .c  o  m*/
        return getYearMonthInt(String.valueOf(cal.get(Calendar.YEAR)),
                String.valueOf(cal.get(Calendar.MONTH) + 1));
    }

    public static Integer getYearMonthInt(String year, String month) {
        int yearInt = Integer.parseInt(year);
        int monthInt = Integer.parseInt(month);
        return yearInt * 12 + (monthInt - 1);
    }
}

Related

  1. getYearFromDate(Date date)
  2. getYearFromDate(Date date)
  3. getYearMonth(Date date)
  4. getYearMonthDay(Date date)
  5. getYearMonthDay(Date date)
  6. getYearMonthOfLastMon(Date date)
  7. getYearNumber(Date date)
  8. getYearOfDate(Date date)
  9. getYearOfThisYear(Date currentdate)