Java SimpleDateFormat format year as "99" and "2099"

Description

Java SimpleDateFormat format year as "99" and "2099"

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

    SimpleDateFormat sdf = new SimpleDateFormat("yy");

    System.out.println("Current year in yy format : " + sdf.format(date));

    // formatting year in yyyy format like 2007, 2008 etc.

    sdf = new SimpleDateFormat("yyyy");
    System.out.println("Current year in yyyy format : " + sdf.format(date));
  }/*from   w w w .  jav a2s.  c  o m*/
}



PreviousNext

Related