Java examples for java.util:Year
The year part of the Calendar date.
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static void main(String[] argv) throws Exception { Calendar c = Calendar.getInstance(); System.out.println(getYear(c)); }/*from w w w. j av a2 s .co m*/ /** * The month part of the Calendar date. * @param c the Calendar from which to extract the month * @return The month as a String (e.g., Year) */ public static String getYear(Calendar c) { SimpleDateFormat f = new SimpleDateFormat("yyyy"); return f.format(c.getTime()).toString(); } }