Java Program to format date with DateFormat.FULL

Java 8Object Oriented ProgrammingProgramming

DateFormat.FULL is a constant for full style pattern.

Firstly, we will create Date object −

Date dt = new Date();
DateFormat dateFormat;

Let us format date for different locale with DateFormat.FULL −

// FRENCH
dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.FRENCH);
// CANADA
dateFormat = DateFormat.getDateInstance(DateFormat. FULL, Locale.CANADA);

The following is an example −

Example

 Live Demo

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
public class Demo {
      public static void main(String args[]) {
      Date dt = new Date();
      DateFormat dateFormat;
      // Date Format FULL constant
      dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.FRENCH);
      System.out.println("Locale FRENCH = " + dateFormat.format(dt));
      dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.GERMANY);
      System.out.println("Locale GERMANY = " + dateFormat.format(dt));
      dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.CHINESE);
      System.out.println("Locale CHINESE = " + dateFormat.format(dt));
      dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.CANADA);
      System.out.println("Locale CANADA = " + dateFormat.format(dt));
      dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.ITALY);
      System.out.println("Locale ITALY = " + dateFormat.format(dt));
      dateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.TAIWAN);
      System.out.println("Locale TAIWAN = " + dateFormat.format(dt));
   }
}

Output

Locale FRENCH = jeudi 22 novembre 2018
Locale GERMANY = Donnerstag, 22. November 2018
Locale CHINESE = 2018年11月22日星期四
Locale CANADA = Thursday, November 22, 2018
Locale ITALY = giovedì 22 novembre 2018
Locale TAIWAN = 2018年11月22日星期四
raja
Published on 19-Dec-2018 10:25:11
Advertisements