Here you can find the source of getYear()
public static int getYear()
//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); } }