Java Year Get getYear(final String date)

Here you can find the source of getYear(final String date)

Description

get Year

License

Open Source License

Declaration

@Deprecated
public static String getYear(final String date) throws ParseException 

Method Source Code

//package com.java2s;
/**//ww  w . ja  va2 s  .  c  o m
 * Copyright (C) 2011 BonitaSoft S.A.
 * BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2.0 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Calendar;

import java.util.Locale;

public class Main {
    /**
     * @deprecated Use DateFormat instead
     */
    @Deprecated
    public static String getYear(final String date) throws ParseException {
        String year = null; // February 27, 2012
        if (date != null && !date.isEmpty()) {
            final DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
            final Calendar cal = Calendar.getInstance(Locale.ENGLISH);
            cal.setTime(df.parse(date));
            year = String.valueOf(cal.get(Calendar.YEAR));
        }
        return year;
    }
}

Related

  1. getYear(Date date)
  2. getYear(Date date)
  3. getYear(Date date, TimeZone timeZone)
  4. getYear(Date dt)
  5. getYear(final Date date)
  6. getYear(final String date)
  7. getYear(int year)
  8. getYear(long date)
  9. getYear(String aDate)