Java中的DateFormatSymbols類的getWeekdays()方法用於以字符串格式獲取日曆的工作日名稱。
用法:
public String[] getWeekdays()
參數:該方法不帶任何參數。
返回值:該方法以字符串格式返回工作日的名稱。
以下示例程序旨在說明getWeekdays()方法的使用。
示例1:
// Java code to demonstrate getWeekdays()
import java.text.DateFormatSymbols;
public class DateFormat_Main {
public static void main(String args[])
{
int i;
// Initializing DateFormatSymbols
String wkdays[]
= new DateFormatSymbols().getWeekdays();
for (i = 1; i < wkdays.length; i++) {
// Displaying the weekdays
System.out.println("Day " + i
+ " = " + wkdays[i]);
}
}
}
輸出:
Day 1 = Sunday Day 2 = Monday Day 3 = Tuesday Day 4 = Wednesday Day 5 = Thursday Day 6 = Friday Day 7 = Saturday
示例2:
// Java code to demonstrate getWeekdays()
import java.text.DateFormatSymbols;
public class DateFormat_Main {
public static void main(String args[])
{
int i;
// Initializing DateFormatSymbols
String wkdays[]
= new DateFormatSymbols().getWeekdays();
for (i = 1; i < wkdays.length / 2; i++) {
// Displaying the weekdays
System.out.println("Day " + i
+ " = " + wkdays[i]);
}
}
}
輸出:
Day 1 = Sunday Day 2 = Monday Day 3 = Tuesday
參考: https://docs.oracle.com/javase/8/docs/api/java/text/DateFormatSymbols.html#getWeekdays–
相關用法
- Java DateFormatSymbols getMonths()用法及代碼示例
- Java DateFormatSymbols getShortMonths()用法及代碼示例
- Java DateFormatSymbols setWeekdays()用法及代碼示例
- Java DateFormatSymbols setShortWeekdays()用法及代碼示例
- Java DateFormatSymbols setMonths()用法及代碼示例
- Java DateFormatSymbols getEras()用法及代碼示例
- Java DateFormatSymbols getAmPmStrings()用法及代碼示例
- Java DateFormatSymbols getAvailableLocales()用法及代碼示例
- Java DateFormatSymbols getShortWeekdays()用法及代碼示例
- Java DateFormatSymbols setShortMonths()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java lang.Long.lowestOneBit()用法及代碼示例
- Java Java lang.Long.byteValue()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 DateFormatSymbols getWeekdays() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。