CalendarUtils (Apache Commons Lang 3.20.0 API)
Description: declaration: package: org.apache.commons.lang3.time, class: CalendarUtils

# Class CalendarUtils

java.lang.Object
org.apache.commons.lang3.time.CalendarUtils

public class CalendarUtils extends Object
Helps use `Calendar`s.

Since:
  3.10

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final CalendarUtils`
  `INSTANCE`
  The singleton instance for `Calendar.getInstance()`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CalendarUtils(Calendar calendar)`
  Creates an instance for the given Calendar.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getDayOfMonth()`
  Gets the current day of month.
  `int`
  `getDayOfYear()`
  Gets the current day of year.
  `static CalendarUtils`
  `getInstance()`
  Creates a new instance based on the current time in the default time zone with the default `Locale.Category.FORMAT` locale.
  `int`
  `getMonth()`
  Gets the current month.
  `int`
  `getYear()`
  Gets the current year.
  `LocalDate`
  `toLocalDate()`
  Converts this instance to a `LocalDate`.
  `LocalDateTime`
  `toLocalDateTime()`
  Converts this instance to a `LocalDateTime`.
  `static LocalDateTime`
  `toLocalDateTime(Calendar calendar)`
  Converts a Calendar to a LocalDateTime.
  `OffsetDateTime`
  `toOffsetDateTime()`
  Converts this instance to a `OffsetDateTime`.
  `static OffsetDateTime`
  `toOffsetDateTime(Calendar calendar)`
  Converts a Calendar to a OffsetDateTime.
  `ZonedDateTime`
  `toZonedDateTime()`
  Converts this instance to a `ZonedDateTime`.
  `static ZonedDateTime`
  `toZonedDateTime(Calendar calendar)`
  Converts a Calendar to a ZonedDateTime.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### INSTANCE

    public static final CalendarUtils INSTANCE
    The singleton instance for `Calendar.getInstance()`. The instance is created when the class is initialized and is based on the current time in the default time zone with the default `Locale.Category.FORMAT` locale.
    See Also:
      - `getInstance()`

- ## Constructor Details

  - ### CalendarUtils

    public CalendarUtils(Calendar calendar)
    Creates an instance for the given Calendar.
    Parameters:
      `calendar` - A Calendar.

- ## Method Details

  - ### getInstance

    public static CalendarUtils getInstance()
    Creates a new instance based on the current time in the default time zone with the default `Locale.Category.FORMAT` locale.
    Returns:
      a new instance.
    Since:
      3.14.0

  - ### toLocalDateTime

    public static LocalDateTime toLocalDateTime(Calendar calendar)
    Converts a Calendar to a LocalDateTime.
    Parameters:
      `calendar` - the Calendar to convert.
    Returns:
      a LocalDateTime.
    Since:
      3.17.0

  - ### toOffsetDateTime

    public static OffsetDateTime toOffsetDateTime(Calendar calendar)
    Converts a Calendar to a OffsetDateTime.
    Parameters:
      `calendar` - the Calendar to convert.
    Returns:
      a OffsetDateTime.
    Since:
      3.17.0

  - ### toZonedDateTime

    public static ZonedDateTime toZonedDateTime(Calendar calendar)
    Converts a Calendar to a ZonedDateTime.
    Parameters:
      `calendar` - the Calendar to convert.
    Returns:
      a ZonedDateTime.
    Since:
      3.17.0

  - ### getDayOfMonth

    public int getDayOfMonth()
    Gets the current day of month.
    Returns:
      the current day of month.

  - ### getDayOfYear

    public int getDayOfYear()
    Gets the current day of year.
    Returns:
      the current day of year.
    Since:
      3.13.0

  - ### getMonth

    public int getMonth()
    Gets the current month.
    Returns:
      the current month.

  - ### getYear

    public int getYear()
    Gets the current year.
    Returns:
      the current year.

  - ### toLocalDate

    public LocalDate toLocalDate()
    Converts this instance to a `LocalDate`.
    Returns:
      a LocalDate.
    Since:
      3.18.0

  - ### toLocalDateTime

    public LocalDateTime toLocalDateTime()
    Converts this instance to a `LocalDateTime`.
    Returns:
      a LocalDateTime.
    Since:
      3.17.0

  - ### toOffsetDateTime

    public OffsetDateTime toOffsetDateTime()
    Converts this instance to a `OffsetDateTime`.
    Returns:
      a OffsetDateTime.
    Since:
      3.17.0

  - ### toZonedDateTime

    public ZonedDateTime toZonedDateTime()
    Converts this instance to a `ZonedDateTime`.
    Returns:
      a ZonedDateTime.
    Since:
      3.17.0