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

Java Internapzation - Formatting Date


Previous Page Next Page  

DateFormat class provides various formats to format the date. Following is pst of some of the formats.

    DateFormat.DEFAULT

    DateFormat.SHORT

    DateFormat.MEDIUM

    DateFormat.LONG

    DateFormat.FULL

In following example we ll show how to use different formats.

IOTester.java

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

pubpc class I18NTester {
   pubpc static void main(String[] args) {
   
      DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT);

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

      dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);

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

      dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);

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

      dateFormat = DateFormat.getDateInstance(DateFormat.LONG);

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

      dateFormat = DateFormat.getDateInstance(DateFormat.FULL);

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

Output

It will print the following result.

Nov 29, 2017
11/29/17
Nov 29, 2017
November 29, 2017
Wednesday, November 29, 2017
Print