DateFormat class provides various formats to format the date. Following is list 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; public class I18NTester { public 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())); } }
It will print the following result.
Nov 29, 2017 11/29/17 Nov 29, 2017 November 29, 2017 Wednesday, November 29, 2017Print