当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。