Java Date to Month getMonth(Date dateParam)

Here you can find the source of getMonth(Date dateParam)

Description

get Month

License

Open Source License

Declaration

public static int getMonth(Date dateParam) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static int getMonth(Date dateParam) {
        if (dateParam == null) {
            throw new IllegalArgumentException("The dateParam  must not be null");
        }/*from w w w  .  j a va  2s .c  o m*/
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(dateParam.getTime());
        return cal.get(Calendar.MONTH) + 1;
    }

    public static long getTime(Date dateParam) {
        if (dateParam == null) {
            throw new IllegalArgumentException("The dateParam  must not be null");
        }
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(dateParam.getTime());

        int hour = cal.get(Calendar.HOUR);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);

        long result = hour * 3600 * 1000 + minute * 60 * 1000 + second * 1000;

        return result;
    }
}

Related

  1. getMonth(Date date)
  2. getMonth(Date date)
  3. getMonth(Date date)
  4. getMonth(Date date)
  5. getMonth(Date date)
  6. getMonth(Date... objects)
  7. getMonth(java.util.Date date)
  8. getMonth(java.util.Date date)
  9. getMonth(java.util.Date date)