Java Year Get getYear()

Here you can find the source of getYear()

Description

get Year

License

Open Source License

Declaration

public static String getYear() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static final String YYYY = "yyyy";
    public final static String YYYY_MM_DD = "yyyy-MM-dd";

    public static String getYear() {
        return format(getCurrDate(), YYYY);
    }/*from w  ww.  jav a2  s.  c  o  m*/

    public static String format(Date date, String pattern) {
        if (date == null)
            return "";
        else
            return getFormatter(pattern).format(date);
    }

    public static String format(Date date) {
        if (date == null)
            return "";
        else
            return getFormatter(YYYY_MM_DD).format(date);
    }

    public static synchronized Date getCurrDate() {
        Calendar calendar = Calendar.getInstance();
        return calendar.getTime();
    }

    private static SimpleDateFormat getFormatter(String parttern) {
        return new SimpleDateFormat(parttern);
    }
}

Related

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