Top Description Fields Constructors Methods
org.apache.commons.lang3.time

public Class CalendarUtils

extends Object
Class Inheritance
Imports
java.time.LocalDate, .LocalDateTime, .OffsetDateTime, .ZoneId, .ZonedDateTime, java.util.Calendar, .Locale, .Locale.Category, .Map, .Objects

Helps use Calendars.
Since
3.10

Field Summary

Modifier and TypeField and Description
private final Calendar
public static final CalendarUtils
INSTANCE

The singleton instance for Calendar#getInstance().

private final Locale

Constructor Summary

AccessConstructor and Description
public
CalendarUtils(final Calendar
A Calendar.
calendar
)

Creates an instance for the given Calendar.

pack-priv
CalendarUtils(final Calendar
A Calendar.
calendar
,
final Locale
A Locale.
locale
)

Creates an instance for the given Calendar.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the current day of month.
getDayOfMonth
()

Gets the current day of month.

public int

Returns:

the current day of year.
getDayOfYear
()

Gets the current day of year.

public static CalendarUtils

Returns:

a new instance.
getInstance
()

Creates a new instance based on the current time in the default time zone with the default Category#FORMAT locale.

pack-priv static CalendarUtils

Returns:

a Calendar.
getInstance
(final Locale
the locale for the week data
locale
)

Gets a CalendarUtils using the default time zone and specified locale.

public int

Returns:

the current month.
getMonth
()

Gets the current month.

pack-priv String[]

Returns:

Styled names of months
getMonthDisplayNames
(final int
Must be a valid Calendar#getDisplayNames(int, int, Locale) month style.
style
)

Gets month names in the requested style.

pack-priv String[]

Returns:

Long names of months
getStandaloneLongMonthNames
()

Gets full standalone month names as used in "LLLL" date formatting.

pack-priv String[]

Returns:

Short names of months
getStandaloneShortMonthNames
()

Gets short standalone month names as used in "LLLL" date formatting.

public int

Returns:

the current year.
getYear
()

Gets the current year.

public LocalDate

Returns:

a LocalDate.
toLocalDate
()

Converts this instance to a LocalDate.

public static LocalDateTime

Returns:

a LocalDateTime.
toLocalDateTime
(final Calendar
the Calendar to convert.
calendar
)

Converts a Calendar to a LocalDateTime.

public LocalDateTime

Returns:

a LocalDateTime.
toLocalDateTime
()

Converts this instance to a LocalDateTime.

public static OffsetDateTime

Returns:

a OffsetDateTime.
toOffsetDateTime
(final Calendar
the Calendar to convert.
calendar
)

Converts a Calendar to a OffsetDateTime.

public OffsetDateTime

Returns:

a OffsetDateTime.
toOffsetDateTime
()

Converts this instance to a OffsetDateTime.

public static ZonedDateTime

Returns:

a ZonedDateTime.
toZonedDateTime
(final Calendar
the Calendar to convert.
calendar
)

Converts a Calendar to a ZonedDateTime.

public ZonedDateTime

Returns:

a ZonedDateTime.
toZonedDateTime
()

Converts this instance to a ZonedDateTime.

private static ZoneId
toZoneId(final Calendar calendar)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

calendarback to summary
private final Calendar calendar
INSTANCEback to summary
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 Category#FORMAT locale.

See Also
CalendarUtils#getInstance()
localeback to summary
private final Locale locale

Constructor Detail

CalendarUtilsback to summary
public CalendarUtils(final Calendar calendar)

Creates an instance for the given Calendar.

Parameters
calendar:Calendar

A Calendar.

CalendarUtilsback to summary
pack-priv CalendarUtils(final Calendar calendar, final Locale locale)

Creates an instance for the given Calendar.

Parameters
calendar:Calendar

A Calendar.

locale:Locale

A Locale.

Method Detail

getDayOfMonthback to summary
public int getDayOfMonth()

Gets the current day of month.

Returns:int

the current day of month.

getDayOfYearback to summary
public int getDayOfYear()

Gets the current day of year.

Returns:int

the current day of year.

Since
3.13.0
getInstanceback to summary
public static CalendarUtils getInstance()

Creates a new instance based on the current time in the default time zone with the default Category#FORMAT locale.

Returns:CalendarUtils

a new instance.

Since
3.14.0
getInstanceback to summary
pack-priv static CalendarUtils getInstance(final 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:Locale

the locale for the week data

Returns:CalendarUtils

a Calendar.

getMonthback to summary
public int getMonth()

Gets the current month.

Returns:int

the current month.

getMonthDisplayNamesback to summary
pack-priv String[] getMonthDisplayNames(final int style)

Gets month names in the requested style.

Parameters
style:int

Must be a valid Calendar#getDisplayNames(int, int, Locale) month style.

Returns:String[]

Styled names of months

getStandaloneLongMonthNamesback to summary
pack-priv String[] getStandaloneLongMonthNames()

Gets full standalone month names as used in "LLLL" date formatting.

Returns:String[]

Long names of months

getStandaloneShortMonthNamesback to summary
pack-priv String[] getStandaloneShortMonthNames()

Gets short standalone month names as used in "LLLL" date formatting.

Returns:String[]

Short names of months

getYearback to summary
public int getYear()

Gets the current year.

Returns:int

the current year.

toLocalDateback to summary
public LocalDate toLocalDate()

Converts this instance to a LocalDate.

Returns:LocalDate

a LocalDate.

Since
3.18.0
toLocalDateTimeback to summary
public static LocalDateTime toLocalDateTime(final Calendar calendar)

Converts a Calendar to a LocalDateTime.

Parameters
calendar:Calendar

the Calendar to convert.

Returns:LocalDateTime

a LocalDateTime.

Since
3.17.0
toLocalDateTimeback to summary
public LocalDateTime toLocalDateTime()

Converts this instance to a LocalDateTime.

Returns:LocalDateTime

a LocalDateTime.

Since
3.17.0
toOffsetDateTimeback to summary
public static OffsetDateTime toOffsetDateTime(final Calendar calendar)

Converts a Calendar to a OffsetDateTime.

Parameters
calendar:Calendar

the Calendar to convert.

Returns:OffsetDateTime

a OffsetDateTime.

Since
3.17.0
toOffsetDateTimeback to summary
public OffsetDateTime toOffsetDateTime()

Converts this instance to a OffsetDateTime.

Returns:OffsetDateTime

a OffsetDateTime.

Since
3.17.0
toZonedDateTimeback to summary
public static ZonedDateTime toZonedDateTime(final Calendar calendar)

Converts a Calendar to a ZonedDateTime.

Parameters
calendar:Calendar

the Calendar to convert.

Returns:ZonedDateTime

a ZonedDateTime.

Since
3.17.0
toZonedDateTimeback to summary
public ZonedDateTime toZonedDateTime()

Converts this instance to a ZonedDateTime.

Returns:ZonedDateTime

a ZonedDateTime.

Since
3.17.0
toZoneIdback to summary
private static ZoneId toZoneId(final Calendar calendar)