Package org.apache.commons.lang3.time
Class CalendarUtils
- java.lang.Object
-
- org.apache.commons.lang3.time.CalendarUtils
-
public class CalendarUtils extends java.lang.Object
Helps useCalendar
s.- Since:
- 3.10
-
-
Field Summary
Fields Modifier and Type Field Description static CalendarUtils
INSTANCE
The singleton instance forCalendar.getInstance()
.
-
Constructor Summary
Constructors Constructor Description CalendarUtils(java.util.Calendar calendar)
Creates an instance for the given Calendar.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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 defaultLocale.Category.FORMAT
locale.int
getMonth()
Gets the current month.int
getYear()
Gets the current year.java.time.LocalDate
toLocalDate()
Converts this instance to aLocalDate
.java.time.LocalDateTime
toLocalDateTime()
Converts this instance to aLocalDateTime
.static java.time.LocalDateTime
toLocalDateTime(java.util.Calendar calendar)
Converts a Calendar to a LocalDateTime.java.time.OffsetDateTime
toOffsetDateTime()
Converts this instance to aOffsetDateTime
.static java.time.OffsetDateTime
toOffsetDateTime(java.util.Calendar calendar)
Converts a Calendar to a OffsetDateTime.java.time.ZonedDateTime
toZonedDateTime()
Converts this instance to aZonedDateTime
.static java.time.ZonedDateTime
toZonedDateTime(java.util.Calendar calendar)
Converts a Calendar to a ZonedDateTime.
-
-
-
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.FORMAT
locale.- See Also:
getInstance()
-
-
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.FORMAT
locale.- Returns:
- a new instance.
- Since:
- 3.14.0
-
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
-
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 java.time.LocalDate toLocalDate()
Converts this instance to aLocalDate
.- Returns:
- a LocalDateTime.
- 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
-
-