Java Year Current getYear()

Here you can find the source of getYear()

Description

get Year

License

Open Source License

Declaration

public static int getYear() 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Oobium, Inc.//  www  .  java 2  s  .  co  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Jeremy Dowdall <jeremy@oobium.com> - initial API and implementation
 ******************************************************************************/

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

public class Main {
    public static int getYear() {
        return getField(new Date(), Calendar.YEAR);
    }

    public static int getYear(Date date) {
        return getField(date, Calendar.YEAR);
    }

    public static int getField(Date date, int field) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(field);
    }

    public static int getField(int field) {
        return getField(new Date(), field);
    }
}

Related

  1. getYear()
  2. getYear()
  3. getYear()
  4. getYear()
  5. getYear()
  6. year()
  7. year()
  8. year()
  9. year()