Java中的DateFormatSymbols類的setShortWeekdays(String [] newShWeekds)方法用於將日曆工作日的短名稱(以字符串格式)設置為一些不同的字符串。例如,可以將“Sun”更改為“FRI”,將“Mon”更改為“WED”等。
用法:
public void setShortWeekdays(String[] newShWeekds)
參數:該方法采用一個參數newShWeekds,它是String類型的數組,表示將在現有工作日中替換的新字符串。
返回值:該方法以字符串格式返回修改後的工作日簡稱。
以下示例程序旨在說明setShortWeekdays()方法的使用。
示例1:
// Java code to demonstrate setShortWeekdays()
import java.text.DateFormatSymbols;
import java.util.Locale;
public class DateFormat_Main {
public static void main(String args[])
{
// Initialising DateFormatSymbols object
DateFormatSymbols format
= new DateFormatSymbols(
new Locale("en", "US"));
// Taking the default short weekdays
String[] shDays
= format.getShortWeekdays();
// Displaying the original
System.out.print("Original: ");
for (int i = 1; i < shDays.length; i++) {
System.out.print(shDays[i] + " ");
}
System.out.println();
// Taking an alternative names
String[] modDays = { "WED", "THU", "FRI",
"MON", "TUE", "SUN", "SAT" };
// Setting the default into modified
format.setShortWeekdays(modDays);
// Displaying the mdified string
String[] modifiedDays
= format.getShortWeekdays();
System.out.print("Modified: ");
for (int i = 0; i < modifiedDays.length; i++) {
System.out.print(modifiedDays[i] + " ");
}
}
}
輸出:
Original: Sun Mon Tue Wed Thu Fri Sat Modified: WED THU FRI MON TUE SUN SAT
示例2:
// Java code to demonstrate setShortWeekdays()
import java.text.DateFormatSymbols;
import java.util.Locale;
public class DateFormat_Main {
public static void main(String args[])
{
// Initialising DateFormatSymbols object
DateFormatSymbols format
= new DateFormatSymbols(
new Locale("en", "US"));
// Taking the default short weekdays
String[] shDays = format.getShortWeekdays();
// Displaying the original
System.out.print("Original: ");
for (int i = 1; i < shDays.length; i++) {
System.out.print(shDays[i] + " ");
}
System.out.println();
// Taking an alternative names with
// additional random strings
String[] modDays = { "WED", "THU", "FRI",
"MON", "TUE", "SUN",
"SAT", "ONE", "TWO" };
// Setting the default into modified
format.setShortWeekdays(modDays);
// Displaying the mdified string
String[] modifiedDays
= format.getShortWeekdays();
System.out.print("Modified: ");
for (int i = 0; i < modifiedDays.length; i++) {
System.out.print(modifiedDays[i] + " ");
}
}
}
輸出:
Original: Sun Mon Tue Wed Thu Fri Sat Modified: WED THU FRI MON TUE SUN SAT ONE TWO
相關用法
- Java DateFormatSymbols getShortMonths()用法及代碼示例
- Java DateFormatSymbols setShortMonths()用法及代碼示例
- Java DateFormatSymbols setMonths()用法及代碼示例
- Java DateFormatSymbols getAvailableLocales()用法及代碼示例
- Java DateFormatSymbols getWeekdays()用法及代碼示例
- Java DateFormatSymbols setWeekdays()用法及代碼示例
- Java DateFormatSymbols getShortWeekdays()用法及代碼示例
- Java DateFormatSymbols getMonths()用法及代碼示例
- Java DateFormatSymbols getEras()用法及代碼示例
- Java DateFormatSymbols getAmPmStrings()用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 DateFormatSymbols setShortWeekdays() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。