Java Date to Year getYear(Date dateParam)

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

Description

get Year

License

Open Source License

Declaration

public static int getYear(Date dateParam) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static int getYear(Date dateParam) {
        if (dateParam == null) {
            throw new IllegalArgumentException("The dateParam  must not be null");
        }// w w w . ja  v  a  2 s  .  co m
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(dateParam.getTime());
        return cal.get(Calendar.YEAR);
    }

    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. getYear(Date date)
  2. getYear(Date date)
  3. getYear(Date date)
  4. getYear(Date date)
  5. getYear(Date date)
  6. getYear(Date start)
  7. getYear(final Date date)
  8. getYear(final Date date)
  9. getYear(final Date date)