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://docs.oracle.com/javase/8/docs/api/java/text/DateFormatSymbols.html#getWeekdays-