Here you can find the source of year()
public static String year()
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static String year() { return now("yyyy"); }//from ww w .jav a2 s .com public static String now(String s) { SimpleDateFormat simpledateformat = new SimpleDateFormat(s); Date date = new Date(); GregorianCalendar gregoriancalendar = new GregorianCalendar(); gregoriancalendar.setTime(date); Date date1 = gregoriancalendar.getTime(); String s1 = simpledateformat.format(date1); return s1; } public static String now(String s, Date date) { SimpleDateFormat simpledateformat = new SimpleDateFormat(s); String s1 = simpledateformat.format(date); return s1; } public static String now() { return now("yyyy-MM-dd HH:mm:ss"); } }