Formatting date in default formats using DateFormat - Java Date Time

Java examples for Date Time:Legacy Date

Description

Formatting date in default formats using DateFormat

Demo Code


import java.text.DateFormat;
import java.util.Date;
 
public class Main {
 
  public static void main(String[] args) {
   /* w  w  w . j av a2  s  . c om*/
    Date date = new Date();
 
    String strDate = DateFormat.getDateInstance(DateFormat.SHORT).format(date);
    System.out.println(strDate);
 
    strDate = DateFormat.getDateInstance(DateFormat.MEDIUM).format(date);
    System.out.println(strDate);    
 
    strDate = DateFormat.getDateInstance(DateFormat.LONG).format(date);
    System.out.println(strDate);
 
    strDate = DateFormat.getDateInstance(DateFormat.FULL).format(date);
    System.out.println(strDate);
  }
}

Result


Related Tutorials