trydateformats.java

来自「Java Classic Examples是我买的两本书:《JAVA经典实例》和」· Java 代码 · 共 32 行

JAVA
32
字号
// Trying date formatting
import java.util.*;
import java.text.*;

public class TryDateFormats
{
  public static void main(String[] args)
  {
    Date today = new Date();
    Locale[] locales = {Locale.US, Locale.UK,
                        Locale.GERMANY, Locale.FRANCE };  

    int[] styles = { DateFormat.FULL,DateFormat.LONG,
                     DateFormat.MEDIUM,DateFormat.SHORT}; 
    DateFormat fmt;
    String[] styleText = { "FULL", "LONG", "MEDIUM", "SHORT"};    

    // Output the date for each local in four styles
    for(int i = 0; i < locales.length; i++)
    {
      System.out.println("\nThe Date for " + 
                         locales[i].getDisplayCountry() + ":");
      for(int j = 0; j < styles.length; j++)
      {
        fmt = DateFormat.getDateInstance(styles[j], locales[i]);
        System.out.println( "\tIn " + styleText[j] + 
                            " is " + fmt.format(today));
      }
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?