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