当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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–



相关用法


注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 DateFormatSymbols getShortWeekdays() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。