Get current year by yyyy - Java java.util

Java examples for java.util:Year

Description

Get current year by yyyy

Demo Code


//package com.java2s;

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

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(year());
    }//from   w w  w .j  a va2s  .c o m

    public static String year() {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        return sdf.format(cal.getTime());

    }
}

Related Tutorials