枚举类DayOfWeek和Month


created: 2022-07-17T16:18:38+08:00
updated: 2022-07-17T17:36:18+08:00
tags:

  • DateTimeAPI
  • DateTimeAPI/DayOfWeek
  • DateTimeAPI/Month

DayOfWeek and Month Enums

Date-Time API 提供了用于指定一周中的几天和一年中的月份的枚举。

DayOfWeek

DayOfWeek 常量的整数值范围从 1(星期一)到 7(星期日)。使用定义的常量 (DayOfWeek.FRIDAY) 使您的代码更具可读性。

这个枚举还提供了许多方法,类似于基于时间的类提供的方法。

System.out.printf("%s%n", DayOfWeek.MONDAY.plus(3));

getDisplayName(TextStyle, Locale)

DayOfWeek dow = DayOfWeek.MONDAY;
Locale locale = Locale.getDefault();
System.out.println(dow.getDisplayName(TextStyle.FULL, locale));
System.out.println(dow.getDisplayName(TextStyle.NARROW, locale));
System.out.println(dow.getDisplayName(TextStyle.SHORT, locale));

en本地输出

Monday
M
Mon

Month

Month 每个常量的整数值对应于从 1(一月)到 12(十二月)的 ISO 范围。使用定义的常量 (Month.SEPTEMBER) 使您的代码更具可读性。

Month 枚举还包括许多方法。

System.out.printf("%d%n", Month.FEBRUARY.maxLength());

getDisplayName(TextStyle, Locale)

Month month = Month.AUGUST;
Locale locale = Locale.getDefault();
System.out.println(month.getDisplayName(TextStyle.FULL, locale));
System.out.println(month.getDisplayName(TextStyle.NARROW, locale));
System.out.println(month.getDisplayName(TextStyle.SHORT, locale));

en本地输出

August
A
Aug

[[日期]]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值