Java examples for Date Time:SimpleDateFormat
Formatting year using SimpleDateFormat
import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] args) { Date date = new Date(); //formatting year in yy format like 07, 08 etc String strDateFormat = "yy"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); /*w ww . ja v a 2 s . c o m*/ System.out.println("Current year in yy format : " + sdf.format(date)); //formatting year in yyyy format like 2007, 2008 etc. strDateFormat = "yyyy"; sdf = new SimpleDateFormat(strDateFormat); System.out.println("Current year in yyyy format : " + sdf.format(date)); } }