當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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 


相關用法


注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 SimpleDateFormat getDateFormatSymbols() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。