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