要获取不同语言环境中“星期几”的显示名称,让我们首先获取默认值-
Locale locale = Locale.getDefault();
现在,假设我们要考虑加拿大的语言环境-
Locale locale1 = Locale.CANADA;
现在,获取区域默认设置和加拿大的星期几名称-
System.out.printf("%s%n", DayOfWeek.THURSDAY.minus(2).getDisplayName(TextStyle.SHORT, locale)); System.out.printf("%s%n", DayOfWeek.THURSDAY.minus(2).getDisplayName(TextStyle.SHORT, locale1));
import java.time.DayOfWeek; import java.time.format.TextStyle; import java.util.Locale; public class Demo { public static void main(String[] args) { Locale locale = Locale.getDefault(); Locale locale1 = Locale.CANADA; System.out.printf("%s%n", DayOfWeek.THURSDAY.minus(2).getDisplayName(TextStyle.SHORT, locale)); System.out.printf("%s%n", DayOfWeek.THURSDAY.minus(2).getDisplayName(TextStyle.SHORT, locale1)); Locale locale2 = Locale.FRENCH; System.out.printf("%s%n", DayOfWeek.SUNDAY.minus(10).getDisplayName(TextStyle.SHORT, locale2)); } }
输出结果
Tue Tue. jeu.