Java中的 DateFormatSymbols getWeekdays() 方法及示例
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: Java/text/DateFormatSymbols.html#getWeekdays–