Technical key: DateFormat class in Java.text Package 1. Get date Formatter public static final DateFormat getdateinstance (int style,locale alocale) This method is used to get the date format objects for the specified style and locale. Parameter description: ①style: Specifies the format style that the formatter object uses for the date, with the optional values of short (using numbers), long (longer description), and full (complete format). ②alocale: Language Environment object used by the formatter. 2. Date format public final string format (date date) The method formats a Date object as a string in the specified format. Parameter Description: Date: the instance object of the dates class. Implementation process:
1 Packagetest;2 3 ImportJava.text.DateFormat;4 Importjava.util.Date;5 ImportJava.util.Locale;6 7 Public classFormatDate {8 9 Public Static voidMain (string[] args) {Ten //TODO auto-generated Method Stub OneDate Date =NewDate (); ADateFormat Formater =dateformat.getdateinstance (Dateformat.full, Locale.china); - //China Date -String string =Formater.format (date); theSYSTEM.OUT.PRINTLN ("China Date: \ t" +string); - //Canada Date -Formater =dateformat.getdateinstance (Dateformat.full, Locale.canada); -System.out.println ("Canada Date: \ t" +Formater.format (date)); + //Japan Date -Formater =dateformat.getdateinstance (Dateformat.full, locale.japan); +SYSTEM.OUT.PRINTLN ("Japan Date: \ t" +Formater.format (date)); A //France Date atFormater =dateformat.getdateinstance (Dateformat.full, locale.france); -SYSTEM.OUT.PRINTLN ("France date: \ t" +Formater.format (date)); - //Germany Date -Formater =dateformat.getdateinstance (Dateformat.full, Locale.german); -System.out.println ("German date: \ t" +Formater.format (date)); - //Italy Date inFormater =dateformat.getdateinstance (Dateformat.full, locale.italy); -System.out.println ("Italian date: \ t" +Formater.format (date)); to } + -}
The output looks like this:
Java instance--formatting the current date