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 Internationalization of application. Following example show how to create and use DateFormat Class.

Example

Open Compiler

importjava.text.DateFormat;importjava.util.Date;importjava.util.Locale;publicclassI18NTester{publicstaticvoidmain(String[] args){Locale locale =newLocale("da","DK");DateFormat dateFormat =DateFormat.getDateInstance();System.out.println(dateFormat.format(newDate()));

      dateFormat =DateFormat.getDateInstance(DateFormat.DEFAULT, locale);System.out.println(dateFormat.format(newDate()));}}

Output

It will print the following result.

Nov 29, 2017
29-11-2017

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *