Java SimpleDateFormat getDateFormatSymbols()方法及示例

Java SimpleDateFormat getDateFormatSymbols()方法及示例

SimpleDateFormat类getDateFormatSymbols() 方法是用来返回日期和时间格式符号的副本。

语法

public DateFormatSymbols getDateFormatSymbols()

参数: 该方法不接受任何参数。

返回值: 该方法返回一份格式符号的副本。

下面的程序说明了SimpleDateFormat的getDateFormatSymbols()方法的工作。

例1 :

// Java code to illustrate
// getDateFormatSymbols() method
  
import java.text.*;
import java.util.*;
  
public class SimpleDateFormat_Demo {
    public static void main(String[] args)
    {
  
        // Initializing the SDF
        SimpleDateFormat SDFormat
            = new SimpleDateFormat();
  
        // Getting al DateFormatSymbols
        DateFormatSymbols DFSymbol
            = SDFormat.getDateFormatSymbols();
  
        // Getting the months
        String[] month = DFSymbol.getShortMonths();
        System.out.println("The Months are: ");
        for (int i = 0; i < month.length; i++) {
            System.out.println(month[i] + " ");
        }
    }
}

输出:

The Months are: 
Jan 
Feb 
Mar 
Apr 
May 
Jun 
Jul 
Aug 
Sep 
Oct 
Nov 
Dec  

例2 :

// Java code to illustrate
// getDateFormatSymbols() method
  
import java.text.*;
import java.util.*;
  
public class SimpleDateFormat_Demo {
    public static void main(String[] args)
    {
  
        // Initializing the SDF
        SimpleDateFormat SDFormat
            = new SimpleDateFormat();
  
        // Getting al DateFormatSymbols
        DateFormatSymbols DFSymbol
            = SDFormat.getDateFormatSymbols();
  
        // Getting the weekdays
        String[] days = DFSymbol.getWeekdays();
        System.out.println("The days of the week are: ");
        for (int i = 0; i < days.length; i++) {
            System.out.println(days[i] + " ");
        }
    }
}

输出:

The days of the week are: 

Sunday 
Monday 
Tuesday 
Wednesday 
Thursday 
Friday 
Saturday 

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程