Enum Class AmPm

java.lang.Object
java.lang.Enum<AmPm>
cloud.opencode.base.date.extra.AmPm
All Implemented Interfaces:
Serializable, Comparable<AmPm>, Constable, TemporalAccessor, TemporalQuery<AmPm>

public enum AmPm extends Enum<AmPm> implements 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:
  • Enum Constant Details

    • AM

      public static final AmPm AM
      AM - Ante Meridiem (before noon, 00:00-11:59) 上午(00:00-11:59)
    • PM

      public static final AmPm PM
      PM - Post Meridiem (after noon, 12:00-23:59) 下午(12:00-23:59)
  • Method Details

    • values

      public static AmPm[] 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

      public static AmPm valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • of

      public static AmPm of(int value)
      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

      public static AmPm ofHour(int hourOfDay)
      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

      public static AmPm from(TemporalAccessor temporal)
      Gets the AmPm from a TemporalAccessor 从TemporalAccessor获取AmPm
      Parameters:
      temporal - the temporal accessor | 时间访问器
      Returns:
      the AmPm | 上午/下午
    • now

      public static AmPm now()
      Gets the current AmPm 获取当前的上午/下午
      Returns:
      the current AmPm | 当前的上午/下午
    • getValue

      public int getValue()
      Gets the value (0=AM, 1=PM) 获取值(0=AM,1=PM)
      Returns:
      the value | 值
    • getShortName

      public String getShortName()
      Gets the short name (AM/PM) 获取短名称(AM/PM)
      Returns:
      the short name | 短名称
    • getChineseName

      public String 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

      public AmPm opposite()
      Gets the opposite period 获取相反的时段
      Returns:
      AM if this is PM, PM if this is AM | 如果是PM返回AM,如果是AM返回PM
    • isSupported

      public boolean isSupported(TemporalField field)
      Specified by:
      isSupported in interface TemporalAccessor
    • getLong

      public long getLong(TemporalField field)
      Specified by:
      getLong in interface TemporalAccessor
    • range

      public ValueRange range(TemporalField field)
      Specified by:
      range in interface TemporalAccessor
    • queryFrom

      public AmPm queryFrom(TemporalAccessor temporal)
      Specified by:
      queryFrom in interface TemporalQuery<AmPm>
    • query

      public static TemporalQuery<AmPm> query()
      Gets a query for extracting the AmPm from a temporal 获取从时间对象提取AmPm的查询
      Returns:
      the AmPm query | AmPm查询
    • getDisplayName

      public String getDisplayName()
      Returns the display name 返回显示名称
      Returns:
      the display name | 显示名称