”;
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
Example
In following example we”ll show how to use different formats.
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())); } }
Output
It will print the following result.
Jun 7, 2024 6/7/24 Jun 7, 2024 June 7, 2024 Friday, June 7, 2024
Advertisements
”;