Java example - format current date

Technical key:
DateFormat class in the java.text package
1. Get a date formatter
public static final DateFormat getDateInstance(int style,Locale aLocale)
This method is used to get a date format object for the specified style and locale.
Parameter Description:
  ①style: Specifies the formatting style used by the formatter object for the date. The optional values ​​are SHORT (using numbers), LONG (longer description) and FULL (full format).
  ②aLocale: The locale object used by the formatter.
 
2. Date formatting
public final String format(Date date)
This method formats a date object as a string in the specified format.
Parameter Description:
  date: An instance object of the date class.
 
Implementation process:
 1 package test;
 2 
 3 import java.text.DateFormat;
 4 import java.util.Date;
 5 import java.util.Locale;
 6 
 7 public class FormatDate {
 8 
 9     public static void main(String[] args) {
10         // TODO Auto-generated method stub
11         Date date = new Date();
12         DateFormat formater = DateFormat.getDateInstance(DateFormat.FULL, Locale.CHINA);
13         //中国日期
14         String string = formater.format(date);
 15          System.out.println("Chinese date: \t" + string);
 16          // Canada date 
17          formater = DateFormat.getDateInstance(DateFormat.FULL, Locale.CANADA);
 18          System.out.println("Canadian date: \t" + formater.format(date));
 19          // Japanese date 
20          formater = DateFormat.getDateInstance(DateFormat.FULL, Locale.JAPAN);
 21          System.out.println( "Japanese date: \t" + formater.format(date));
 22          // French date 
23          formater =DateFormat.getDateInstance(DateFormat.FULL, Locale.FRANCE);
 24          System.out.println("French date: \t" + formater.format(date));
 25          // German date 
26          formater = DateFormat.getDateInstance(DateFormat. FULL, Locale.GERMAN);
 27          System.out.println("German date: \t" + formater.format(date));
 28          // Italian date 
29          formater = DateFormat.getDateInstance(DateFormat.FULL, Locale.ITALY) ;
 30          System.out.println("Italian date: \t" + formater.format(date));
 31      }
 32  
33 }
 
The output is shown below:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325282307&siteId=291194637