Java Year Get getYear(Date date, TimeZone timeZone)

Here you can find the source of getYear(Date date, TimeZone timeZone)

Description

get Year

License

Open Source License

Declaration

public static int getYear(Date date, TimeZone timeZone) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.TimeZone;

public class Main {
    private static final SimpleDateFormat _fmtYear = new SimpleDateFormat("yyyy");

    public static int getYear(Date date, TimeZone timeZone) {
        if (date == null)
            throw new IllegalArgumentException("date is required.");
        if (timeZone == null)
            timeZone = TimeZone.getDefault();
        _fmtYear.setTimeZone(timeZone);//from www  .  j a v a 2 s  . co m
        try {
            return Integer.parseInt(_fmtYear.format(date));
        } catch (NumberFormatException e) {
            throw new IllegalStateException("Failed to format date : " + e.getMessage());
        }
    }
}

Related

  1. getYear(Date date)
  2. getYear(Date date)
  3. getYear(Date date)
  4. getYear(Date date)
  5. getYear(Date date)
  6. getYear(Date dt)
  7. getYear(final Date date)
  8. getYear(final String date)
  9. getYear(final String date)