Java Year From getYear(boolean fourDigit)

Here you can find the source of getYear(boolean fourDigit)

Description

Returns the current Year as a string (e.g.

License

Open Source License

Return

the current year as a string.

Declaration

public static String getYear(boolean fourDigit) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2005-2012 Synopsys, Incorporated
 * 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://from  w w  w.j a va  2  s  .  c  o m
 * Synopsys, Inc - Initial implementation 
 *******************************************************************************/

import java.util.Calendar;

public class Main {
    private static Calendar mCalendar = null;

    /**
     * Returns the current Year as a string (e.g. 2003).
     * @return the current year as a string.
     */
    public static String getYear(boolean fourDigit) {
        if (mCalendar == null)
            Init();
        String year = mCalendar.get(Calendar.YEAR) + "";
        if (year.length() == 4 && fourDigit)
            return year;
        return year.substring(2);
    }

    /**
     * This method creates a new Calendar object
     */
    public static void Init() {
        mCalendar = Calendar.getInstance();
    }
}

Related

  1. getYear(int num)
  2. getYear(long t)
  3. getYearBegin(int year)
  4. getYearFirst(int year)