Class CalendarUtils

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

public class CalendarUtils extends Object
Helps use Calendars.
Since:
3.10
  • Field Details

  • Constructor Details

    • CalendarUtils

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

      CalendarUtils(Calendar calendar, Locale locale)
      Creates an instance for the given Calendar.
      Parameters:
      calendar - A Calendar.
      locale - A Locale.
  • 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
    • getInstance

      static CalendarUtils getInstance(Locale locale)
      Gets a CalendarUtils using the default time zone and specified locale. The CalendarUtils returned is based on the current time in the default time zone with the given locale.
      Parameters:
      locale - the locale for the week data
      Returns:
      a Calendar.
    • 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
    • toZoneId

      private static ZoneId toZoneId(Calendar calendar)
    • 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.
    • getMonthDisplayNames

      String[] getMonthDisplayNames(int style)
      Gets month names in the requested style.
      Parameters:
      style - Must be a valid Calendar.getDisplayNames(int, int, Locale) month style.
      Returns:
      Styled names of months
    • getStandaloneLongMonthNames

      String[] getStandaloneLongMonthNames()
      Gets full standalone month names as used in "LLLL" date formatting.
      Returns:
      Long names of months
    • getStandaloneShortMonthNames

      String[] getStandaloneShortMonthNames()
      Gets short standalone month names as used in "LLLL" date formatting.
      Returns:
      Short names of months
    • getYear

      public int getYear()
      Gets the current year.
      Returns:
      the current year.
    • 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