Package org.apache.commons.lang3.time
Class CalendarUtils
java.lang.Object
org.apache.commons.lang3.time.CalendarUtils
Helps use
Calendar
s.- Since:
- 3.10
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Calendar
static final CalendarUtils
The singleton instance forCalendar.getInstance()
.private final Locale
-
Constructor Summary
ConstructorsConstructorDescriptionCalendarUtils
(Calendar calendar) Creates an instance for the given Calendar.CalendarUtils
(Calendar calendar, Locale locale) Creates an instance for the given Calendar. -
Method Summary
Modifier and TypeMethodDescriptionint
Gets the current day of month.int
Gets the current day of year.static CalendarUtils
Creates a new instance based on the current time in the default time zone with the defaultLocale.Category.FORMAT
locale.(package private) static CalendarUtils
getInstance
(Locale locale) Gets a CalendarUtils using the default time zone and specified locale.int
getMonth()
Gets the current month.(package private) String[]
getMonthDisplayNames
(int style) Gets month names in the requested style.(package private) String[]
Gets full standalone month names as used in "LLLL" date formatting.(package private) String[]
Gets short standalone month names as used in "LLLL" date formatting.int
getYear()
Gets the current year.Converts this instance to aLocalDateTime
.static LocalDateTime
toLocalDateTime
(Calendar calendar) Converts a Calendar to a LocalDateTime.Converts this instance to aOffsetDateTime
.static OffsetDateTime
toOffsetDateTime
(Calendar calendar) Converts a Calendar to a OffsetDateTime.Converts this instance to aZonedDateTime
.static ZonedDateTime
toZonedDateTime
(Calendar calendar) Converts a Calendar to a ZonedDateTime.private static ZoneId
-
Field Details
-
INSTANCE
The singleton instance forCalendar.getInstance()
. The instance is created when the class is initialized and is based on the current time in the default time zone with the defaultLocale.Category.FORMAT
locale.- See Also:
-
calendar
-
locale
-
-
Constructor Details
-
CalendarUtils
Creates an instance for the given Calendar.- Parameters:
calendar
- A Calendar.
-
CalendarUtils
Creates an instance for the given Calendar.- Parameters:
calendar
- A Calendar.locale
- A Locale.
-
-
Method Details
-
getInstance
Creates a new instance based on the current time in the default time zone with the defaultLocale.Category.FORMAT
locale.- Returns:
- a new instance.
- Since:
- 3.14.0
-
getInstance
Gets a CalendarUtils using the default time zone and specified locale. TheCalendarUtils
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
Converts a Calendar to a LocalDateTime.- Parameters:
calendar
- the Calendar to convert.- Returns:
- a LocalDateTime.
- Since:
- 3.17.0
-
toOffsetDateTime
Converts a Calendar to a OffsetDateTime.- Parameters:
calendar
- the Calendar to convert.- Returns:
- a OffsetDateTime.
- Since:
- 3.17.0
-
toZonedDateTime
Converts a Calendar to a ZonedDateTime.- Parameters:
calendar
- the Calendar to convert.- Returns:
- a ZonedDateTime.
- Since:
- 3.17.0
-
toZoneId
-
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
Gets month names in the requested style.- Parameters:
style
- Must be a validCalendar.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
Converts this instance to aLocalDateTime
.- Returns:
- a LocalDateTime.
- Since:
- 3.17.0
-
toOffsetDateTime
Converts this instance to aOffsetDateTime
.- Returns:
- a OffsetDateTime.
- Since:
- 3.17.0
-
toZonedDateTime
Converts this instance to aZonedDateTime
.- Returns:
- a ZonedDateTime.
- Since:
- 3.17.0
-