Java DateFormat format Date and time with all styles

Description

Java DateFormat format Date and time with all styles

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
  public static void main(String[] args) throws Exception {
    Locale currentLocale = new Locale("fr", "FR");

    Date today;//w  w  w  .jav a2s.c o  m
    String result;
    DateFormat formatter;

    int[] styles = { DateFormat.DEFAULT, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL };

    System.out.println();
    System.out.println("Locale: " + currentLocale.toString());
    System.out.println();

    today = new Date();

    for (int k = 0; k < styles.length; k++) {
      formatter = DateFormat.getDateTimeInstance(styles[k], styles[k], currentLocale);
      result = formatter.format(today);
      System.out.println(result);
    }
  }
}



PreviousNext

Related