Formatting a date using SimpleDateFormat

Use SimpleDateFormat.

Main.java:

import java.util.*;
import java.text.*;
 
public class Main
{
   public static void main(String []args) {
      SimpleDateFormat formatter = null;
 
      Date currentDate = new Date();
 
      String[] patterns = { 
         "hh:mm:ss          ",
         "MMM yyyy          ",
         "MM/yy             ",
         "h'hr' mm'min'     ",
         "SSSSS             ",
         "ww 'out of 52'    ",
         "z                 ",
         "dd/MM/yyyy - kk:mm",
      };
 
      for (int i=0; i<patterns.length; i++) {
         formatter = new SimpleDateFormat(patterns[i]);
         System.out.println(patterns[i] + "t" + formatter.format(currentDate));
      }
   }
}

outputs:

hh:mm:ss                08:26:30
MMM yyyy                Dec 2002
MM/yy                   12/02
h'hr' mm'min'           8hr 26min
SSSSS                   00755
ww 'out of 52'          51 out of 52
z                       CET
dd/MM/yyyy - kk:mm      15/12/2002 - 20:26