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
相關用法
- Java SimpleDateFormat parse()用法及代碼示例
- Java SimpleDateFormat equals()用法及代碼示例
- Java SimpleDateFormat set2DigitYearStart()用法及代碼示例
- Java SimpleDateFormat format()用法及代碼示例
- Java SimpleDateFormat toLocalizedPattern()用法及代碼示例
- Java SimpleDateFormat toPattern()用法及代碼示例
- Java SimpleDateFormat applyPattern()用法及代碼示例
- Java SimpleDateFormat setDateFormatSymbols()用法及代碼示例
- Java SimpleDateFormat clone()用法及代碼示例
- Java SimpleDateFormat get2DigitYearStart()用法及代碼示例
- Java SimpleDateFormat hashCode()用法及代碼示例
- Java SimpleDateFormat applyLocalizedPattern()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 SimpleDateFormat getDateFormatSymbols() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。