Enum Class AmPm
- All Implemented Interfaces:
Serializable, Comparable<AmPm>, Constable, TemporalAccessor, TemporalQuery<AmPm>
AmPm enum representing AM (ante meridiem) and PM (post meridiem)
上午/下午枚举,表示上午(AM)和下午(PM)
This enum represents the two halves of the day: AM (00:00-11:59) and PM (12:00-23:59).
此枚举表示一天的两半:上午(00:00-11:59)和下午(12:00-23:59)。
Features | 主要功能:
- AM/PM representation with bilingual names - 上午/下午表示,支持双语名称
- Create from hour, value, or TemporalAccessor - 从小时、值或TemporalAccessor创建
- TemporalAccessor and TemporalQuery implementations - 实现TemporalAccessor和TemporalQuery
- Hour range queries (firstHour, lastHour) - 小时范围查询
Usage Examples | 使用示例:
AmPm am = AmPm.AM;
AmPm pm = AmPm.PM;
AmPm current = AmPm.from(LocalTime.now());
boolean isAm = current.isAm();
Security | 安全性:
- Thread-safe: Yes (enum is inherently thread-safe) - 线程安全: 是(枚举本身是线程安全的)
- Immutable: Yes - 不可变: 是
- Since:
- JDK 25, opencode-base-date V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionintGets the first hour of this period (0 for AM, 12 for PM) 获取此时段的第一个小时(AM为0,PM为12)static AmPmfrom(TemporalAccessor temporal) Gets the AmPm from a TemporalAccessor 从TemporalAccessor获取AmPmGets the Chinese name (上午/下午) 获取中文名称(上午/下午)Returns the display name 返回显示名称longgetLong(TemporalField field) Gets the short name (AM/PM) 获取短名称(AM/PM)intgetValue()Gets the value (0=AM, 1=PM) 获取值(0=AM,1=PM)booleanisAm()Checks if this is AM 检查是否为上午booleanisPm()Checks if this is PM 检查是否为下午booleanisSupported(TemporalField field) intlastHour()Gets the last hour of this period (11 for AM, 23 for PM) 获取此时段的最后一个小时(AM为11,PM为23)static AmPmnow()Gets the current AmPm 获取当前的上午/下午static AmPmof(int value) Gets the AmPm from a value (0=AM, 1=PM) 从值获取AmPm(0=AM,1=PM)static AmPmofHour(int hourOfDay) Gets the AmPm from an hour (0-23) 从小时获取AmPm(0-23)opposite()Gets the opposite period 获取相反的时段static TemporalQuery<AmPm> query()Gets a query for extracting the AmPm from a temporal 获取从时间对象提取AmPm的查询queryFrom(TemporalAccessor temporal) range(TemporalField field) static AmPmReturns the enum constant of this class with the specified name.static AmPm[]values()Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOfMethods inherited from interface TemporalAccessor
get, query
-
Enum Constant Details
-
AM
AM - Ante Meridiem (before noon, 00:00-11:59) 上午(00:00-11:59) -
PM
PM - Post Meridiem (after noon, 12:00-23:59) 下午(12:00-23:59)
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
of
Gets the AmPm from a value (0=AM, 1=PM) 从值获取AmPm(0=AM,1=PM)- Parameters:
value- the value (0 or 1) | 值(0或1)- Returns:
- the AmPm | 上午/下午
-
ofHour
Gets the AmPm from an hour (0-23) 从小时获取AmPm(0-23)- Parameters:
hourOfDay- the hour of day (0-23) | 一天中的小时(0-23)- Returns:
- the AmPm | 上午/下午
-
from
Gets the AmPm from a TemporalAccessor 从TemporalAccessor获取AmPm- Parameters:
temporal- the temporal accessor | 时间访问器- Returns:
- the AmPm | 上午/下午
-
now
-
getValue
public int getValue()Gets the value (0=AM, 1=PM) 获取值(0=AM,1=PM)- Returns:
- the value | 值
-
getShortName
-
getChineseName
Gets the Chinese name (上午/下午) 获取中文名称(上午/下午)- Returns:
- the Chinese name | 中文名称
-
isAm
public boolean isAm()Checks if this is AM 检查是否为上午- Returns:
- true if AM | 如果是上午返回true
-
isPm
public boolean isPm()Checks if this is PM 检查是否为下午- Returns:
- true if PM | 如果是下午返回true
-
firstHour
public int firstHour()Gets the first hour of this period (0 for AM, 12 for PM) 获取此时段的第一个小时(AM为0,PM为12)- Returns:
- the first hour | 第一个小时
-
lastHour
public int lastHour()Gets the last hour of this period (11 for AM, 23 for PM) 获取此时段的最后一个小时(AM为11,PM为23)- Returns:
- the last hour | 最后一个小时
-
opposite
Gets the opposite period 获取相反的时段- Returns:
- AM if this is PM, PM if this is AM | 如果是PM返回AM,如果是AM返回PM
-
isSupported
- Specified by:
isSupportedin interfaceTemporalAccessor
-
getLong
- Specified by:
getLongin interfaceTemporalAccessor
-
range
- Specified by:
rangein interfaceTemporalAccessor
-
queryFrom
- Specified by:
queryFromin interfaceTemporalQuery<AmPm>
-
query
Gets a query for extracting the AmPm from a temporal 获取从时间对象提取AmPm的查询- Returns:
- the AmPm query | AmPm查询
-
getDisplayName
-