java.time.DayOfWeek的getDisplayName()方法是Java中的一个内置函数,它根据指定的Locale类参数和TextStyle返回day-of-week的文本表示形式。 TextStyle定义了三个元素“ FULL”,“ SHORT”和“ NARROW”。语言环境类别代表世界上特定的语言和地区。
方法声明:
public String getDisplayName(TextStyle style, Locale locale)
用法:
String text = dayOfWeekObject.getDisplayName(TextStyle style, Locale locale)
参数:此方法有两个参数:
- style–是TestStyle,可以包含三个元素“ FULL”,“ SHORT”和“ NARROW”。
- locale–代表世界上特定的语言和地区。默认语言环境是US
- dayOfWeekObject–是DayOfWeek的实例。
返回值:该函数返回根据指定的Locale类参数和TextStyle返回day-of-week的文本表示形式。
以下示例程序旨在说明上述方法:
示例1:
// Java Program Demonstrate getDisplayName()
// method of DayOfWeek
import java.time.*;
import java.time.format.TextStyle;
import java.util.Locale;
class DayOfWeekExample {
public static void main(String[] args)
{
// Initializing a DayOfWeek instance
DayOfWeek dayOfWeek = DayOfWeek.MONDAY;
// Get textual representation of the
// day-of-week in FULL style
String full_name
= dayOfWeek
.getDisplayName(TextStyle.FULL,
Locale.getDefault());
// Get textual representation of the
// day-of-week in SHORT style
String short_name
= dayOfWeek
.getDisplayName(TextStyle.SHORT,
Locale.getDefault());
// Get textual representation of the
// day-of-week in NARROW style
String narrow_name
= dayOfWeek
.getDisplayName(TextStyle.NARROW,
Locale.getDefault());
// Printing the textual names of the day-of-week
System.out.println(full_name);
System.out.println(short_name);
System.out.println(narrow_name);
}
}
输出:
Monday Mon M
示例2:
// Java Program Demonstrate getDisplayName()
// method of DayOfWeek
import java.time.*;
import java.time.DayOfWeek;
import java.time.format.TextStyle;
import java.util.Locale;
class DayOfWeekExample {
public static void main(String[] args)
{
// Initializing a DayOfWeek instance
DayOfWeek dayOfWeek = DayOfWeek.WEDNESDAY;
// Get textual representation of the
// day-of-week in FULL style
String full_name
= dayOfWeek
.getDisplayName(TextStyle.FULL,
Locale.getDefault());
// Get textual representation of the
// day-of-week in SHORT style
String short_name
= dayOfWeek
.getDisplayName(TextStyle.SHORT,
Locale.getDefault());
// Get textual representation of the
// day-of-week in NARROW style
String narrow_name
= dayOfWeek
.getDisplayName(TextStyle.NARROW,
Locale.getDefault());
// Printing the textual names of the day-of-week
System.out.println(full_name);
System.out.println(short_name);
System.out.println(narrow_name);
}
}
输出:
Wednesday Wed W
相关用法
- Java TimeZone getDisplayName()用法及代码示例
- Java Locale getDisplayName()用法及代码示例
- Java ZoneOffset getDisplayName()用法及代码示例
- Java ZoneId getDisplayName()用法及代码示例
- Java Calendar getDisplayName()用法及代码示例
- Java TimeZone getDisplayName(boolean, int)用法及代码示例
- Java DayOfWeek of()用法及代码示例
- Java DayOfWeek from()用法及代码示例
- Java DayOfWeek plus()用法及代码示例
- Java DayOfWeek get()用法及代码示例
- Java DayOfWeek minus()用法及代码示例
- Java DayOfWeek valueOf()用法及代码示例
- Java DayOfWeek adjustInto()用法及代码示例
- Java DayOfWeek getValue()用法及代码示例
- Java DayOfWeek values()用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 DayOfWeek getDisplayName() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。