Java Internalization - DateFormat Class



java.text.DateFormat class formats dates as per the locale. As different coutries use different formats to display dates. This class is extremely useful in dealing with dates in internalization of application. Following example show how to create and use DateFormat Class.

IOTester.java

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

public class I18NTester {
   public static void main(String[] args) {
      Locale locale = new Locale("da","DK");

      DateFormat dateFormat = DateFormat.getDateInstance();

      System.out.println(dateFormat.format(new Date()));

      dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);

      System.out.println(dateFormat.format(new Date()));
   }
}

Output

It will print the following result.

Nov 29, 2017
29-11-2017
Print
Advertisements