Package org.apache.commons.lang3.time
Class CalendarUtils
- java.lang.Object
-
- org.apache.commons.lang3.time.CalendarUtils
-
public class CalendarUtils extends java.lang.ObjectHelps useCalendars.- Since:
- 3.10
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Calendarcalendarstatic CalendarUtilsINSTANCEThe singleton instance forCalendar.getInstance().private java.util.Localelocale
-
Constructor Summary
Constructors Constructor Description CalendarUtils(java.util.Calendar calendar)Creates an instance for the given Calendar.CalendarUtils(java.util.Calendar calendar, java.util.Locale locale)Creates an instance for the given Calendar.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetDayOfMonth()Gets the current day of month.intgetDayOfYear()Gets the current day of year.static CalendarUtilsgetInstance()Creates a new instance based on the current time in the default time zone with the defaultLocale.Category.FORMATlocale.(package private) static CalendarUtilsgetInstance(java.util.Locale locale)Gets a CalendarUtils using the default time zone and specified locale.intgetMonth()Gets the current month.(package private) java.lang.String[]getMonthDisplayNames(int style)Gets month names in the requested style.(package private) java.lang.String[]getStandaloneLongMonthNames()Gets full standalone month names as used in "LLLL" date formatting.(package private) java.lang.String[]getStandaloneShortMonthNames()Gets short standalone month names as used in "LLLL" date formatting.intgetYear()Gets the current year.java.time.LocalDatetoLocalDate()Converts this instance to aLocalDate.java.time.LocalDateTimetoLocalDateTime()Converts this instance to aLocalDateTime.static java.time.LocalDateTimetoLocalDateTime(java.util.Calendar calendar)Converts a Calendar to a LocalDateTime.java.time.OffsetDateTimetoOffsetDateTime()Converts this instance to aOffsetDateTime.static java.time.OffsetDateTimetoOffsetDateTime(java.util.Calendar calendar)Converts a Calendar to a OffsetDateTime.java.time.ZonedDateTimetoZonedDateTime()Converts this instance to aZonedDateTime.static java.time.ZonedDateTimetoZonedDateTime(java.util.Calendar calendar)Converts a Calendar to a ZonedDateTime.private static java.time.ZoneIdtoZoneId(java.util.Calendar calendar)
-
-
-
Field Detail
-
INSTANCE
public static final CalendarUtils 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.FORMATlocale.- See Also:
getInstance()
-
calendar
private final java.util.Calendar calendar
-
locale
private final java.util.Locale locale
-
-
Constructor Detail
-
CalendarUtils
public CalendarUtils(java.util.Calendar calendar)
Creates an instance for the given Calendar.- Parameters:
calendar- A Calendar.
-
CalendarUtils
CalendarUtils(java.util.Calendar calendar, java.util.Locale locale)Creates an instance for the given Calendar.- Parameters:
calendar- A Calendar.locale- A Locale.
-
-
Method Detail
-
getInstance
public static CalendarUtils getInstance()
Creates a new instance based on the current time in the default time zone with the defaultLocale.Category.FORMATlocale.- Returns:
- a new instance.
- Since:
- 3.14.0
-
getInstance
static CalendarUtils getInstance(java.util.Locale locale)
Gets a CalendarUtils using the default time zone and specified locale. TheCalendarUtilsreturned 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 java.time.LocalDateTime toLocalDateTime(java.util.Calendar calendar)
Converts a Calendar to a LocalDateTime.- Parameters:
calendar- the Calendar to convert.- Returns:
- a LocalDateTime.
- Since:
- 3.17.0
-
toOffsetDateTime
public static java.time.OffsetDateTime toOffsetDateTime(java.util.Calendar calendar)
Converts a Calendar to a OffsetDateTime.- Parameters:
calendar- the Calendar to convert.- Returns:
- a OffsetDateTime.
- Since:
- 3.17.0
-
toZonedDateTime
public static java.time.ZonedDateTime toZonedDateTime(java.util.Calendar calendar)
Converts a Calendar to a ZonedDateTime.- Parameters:
calendar- the Calendar to convert.- Returns:
- a ZonedDateTime.
- Since:
- 3.17.0
-
toZoneId
private static java.time.ZoneId toZoneId(java.util.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
java.lang.String[] getMonthDisplayNames(int style)
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
java.lang.String[] getStandaloneLongMonthNames()
Gets full standalone month names as used in "LLLL" date formatting.- Returns:
- Long names of months
-
getStandaloneShortMonthNames
java.lang.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.
-
toLocalDate
public java.time.LocalDate toLocalDate()
Converts this instance to aLocalDate.- Returns:
- a LocalDate.
- Since:
- 3.18.0
-
toLocalDateTime
public java.time.LocalDateTime toLocalDateTime()
Converts this instance to aLocalDateTime.- Returns:
- a LocalDateTime.
- Since:
- 3.17.0
-
toOffsetDateTime
public java.time.OffsetDateTime toOffsetDateTime()
Converts this instance to aOffsetDateTime.- Returns:
- a OffsetDateTime.
- Since:
- 3.17.0
-
toZonedDateTime
public java.time.ZonedDateTime toZonedDateTime()
Converts this instance to aZonedDateTime.- Returns:
- a ZonedDateTime.
- Since:
- 3.17.0
-
-