SimpleDateFormat類的setDateFormatSymbols()方法用於設置此日期格式的日期和時間格式符號。
用法:
public void setDateFormatSymbols(DateFormatSymbols newFormatSymbols)
參數:該方法采用一個參數newFormatSymbols,該參數表示要將此Date格式設置為的新格式符號。
返回值:該方法返回void類型。
以下示例程序旨在說明SimpleDateFormat的setDateFormatSymbols()方法的用法:
示例1:
// Java code to illustrate
// DateFormatSymbols() method
import java.text.*;
import java.util.*;
public class SimpleDateFormat_Demo {
public static void main(String[] args)
throws InterruptedException, ParseException
{
// Initializing SimpleDateFormat
SimpleDateFormat SDFormat
= new SimpleDateFormat();
// Setting the DateFormatSymbols
DateFormatSymbols DFSymbols
= new DateFormatSymbols(
new Locale("en",
"US"));
// Illustrating the set method
SDFormat.setDateFormatSymbols(DFSymbols);
// Displaying the formats
Date date = new Date();
String str_Date1 = SDFormat.format(date);
System.out.println("The SimpleDateFormat: "
+ (str_Date1));
// Working of DFS
String[] the_days
= DFSymbols.getShortWeekdays();
int i, j = 1;
for (i = 1; i < the_days.length; i++) {
System.out.print("Day" + j++ + " : "
+ the_days[i] + "\n");
}
}
}
輸出:
The SimpleDateFormat: 1/30/19 10:27 AM Day1 : Sun Day2 : Mon Day3 : Tue Day4 : Wed Day5 : Thu Day6 : Fri Day7 : Sat
示例2:
// Java code to illustrate
// DateFormatSymbols() method
import java.text.*;
import java.util.*;
public class SimpleDateFormat_Demo {
public static void main(String[] args)
throws InterruptedException, ParseException
{
// Initializing SimpleDateFormat
SimpleDateFormat SDFormat
= new SimpleDateFormat();
// Setting the DateFormatSymbols
DateFormatSymbols DFSymbols
= new DateFormatSymbols(
new Locale("es",
"XL"));
// Illustrating the set method
SDFormat.setDateFormatSymbols(DFSymbols);
// Displaying the formats
Date date = new Date();
String str_Date1 = SDFormat.format(date);
System.out.println("The SimpleDateFormat: "
+ (str_Date1));
// Working of DFS
String[] the_days
= DFSymbols.getShortWeekdays();
int i, j = 1;
for (i = 1; i < the_days.length; i++) {
System.out.print("Day" + j++ + " : "
+ the_days[i] + "\n");
}
}
}
輸出:
The SimpleDateFormat: 1/30/19 10:28 AM Day1 : dom Day2 : lun Day3 : mar Day4 : mi? Day5 : jue Day6 : vie Day7 : s?b
相關用法
- Java SimpleDateFormat getDateFormatSymbols()用法及代碼示例
- Java SimpleDateFormat toLocalizedPattern()用法及代碼示例
- Java SimpleDateFormat applyPattern()用法及代碼示例
- Java SimpleDateFormat equals()用法及代碼示例
- Java SimpleDateFormat set2DigitYearStart()用法及代碼示例
- Java SimpleDateFormat toPattern()用法及代碼示例
- Java SimpleDateFormat parse()用法及代碼示例
- Java SimpleDateFormat get2DigitYearStart()用法及代碼示例
- Java SimpleDateFormat clone()用法及代碼示例
- Java SimpleDateFormat hashCode()用法及代碼示例
- Java SimpleDateFormat applyLocalizedPattern()用法及代碼示例
- Java SimpleDateFormat format()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 SimpleDateFormat setDateFormatSymbols() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。