Java中的 DateFormatSymbols getShortWeekdays() 方法及示例
Java中DateFormatSymbols 类的getShortWeekdays()方法用于获取字符串格式的日历星期几的短名称。例如,“Sun”代表星期日,“Mon”代表星期一等。
句法:
public String[] getShortWeekdays()
参数:该方法不带任何参数。
返回值:该方法以字符串格式返回工作日的简称。
下面的程序说明了 getShortWeekdays() 方法的使用。
示例 1:
// Java code to demonstrate getShortWeekdays()
import java.text.DateFormatSymbols;
public class DateFormat_Main {
public static void main(String args[])
{
int i;
// Initializing DateFormatSymbols
String shwkdays[]
= new DateFormatSymbols().getShortWeekdays();
for (i = 1; i < shwkdays.length; i++) {
// Displaying the short names of weekdays
System.out.println("Day " + i
+ " = " + shwkdays[i]);
}
}
}
输出:
Day 1 = Sun
Day 2 = Mon
Day 3 = Tue
Day 4 = Wed
Day 5 = Thu
Day 6 = Fri
Day 7 = Sat
示例 2:
// Java code to demonstrate getShortWeekdays()
import java.text.DateFormatSymbols;
public class DateFormat_Main {
public static void main(String args[])
{
int i;
// Initializing DateFormatSymbols
String shwkdays[]
= new DateFormatSymbols().getShortWeekdays();
for (i = 1; i < shwkdays.length / 2; i++) {
// Displaying the short names of weekdays
System.out.println("Day " + i
+ " = " + shwkdays[i]);
}
}
}
输出:
Day 1 = Sun
Day 2 = Mon
Day 3 = Tue
参考: https: Java/text/DateFormatSymbols.html#getShortWeekdays–