English 中文(简体)
JAVA I18N - DateFormat Class
  • 时间:2024-12-22

Java Internapzation - DateFormat Class


Previous Page Next Page  

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 deapng with dates in internapzation of apppcation. Following example show how to create and use DateFormat Class.

IOTester.java

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

pubpc class I18NTester {
   pubpc 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