CalendarUtils

public class org.apache.commons.lang3.time.CalendarUtils[source]

Helps use Calendars.

Since:

3.10

Constructors

CalendarUtils(Calendar calendar)

Creates an instance for the given Calendar.

public CalendarUtils(Calendar calendar)[source]

Creates an instance for the given Calendar.

Parameters:

calendar – A Calendar.

Fields and constants

static final CalendarUtils

INSTANCE

The singleton instance for Calendar.getInstance().

public static final CalendarUtils INSTANCE[source]

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 Locale.Category.FORMAT locale.

See also:

getInstance()

Methods

int

getDayOfMonth()

Gets the current day of month.

int

getDayOfYear()

Gets the current day of year.

static CalendarUtils

getInstance()

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

int

getMonth()

Gets the current month.

int

getYear()

Gets the current year.

LocalDate

toLocalDate()

Converts this instance to a LocalDate.

LocalDateTime

toLocalDateTime()

Converts this instance to a LocalDateTime.

static LocalDateTime

toLocalDateTime(Calendar calendar)

Converts a Calendar to a LocalDateTime.

OffsetDateTime

toOffsetDateTime()

Converts this instance to a OffsetDateTime.

static OffsetDateTime

toOffsetDateTime(Calendar calendar)

Converts a Calendar to an OffsetDateTime.

ZonedDateTime

toZonedDateTime()

Converts this instance to a ZonedDateTime.

static ZonedDateTime

toZonedDateTime(Calendar calendar)

Converts a Calendar to a ZonedDateTime.

public int getDayOfMonth()[source]

Gets the current day of month.

Returns:

The current day of month.

public int getDayOfYear()[source]

Gets the current day of year.

Returns:

The current day of year.

Since:

3.13.0

public static CalendarUtils getInstance()[source]

Gets 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

public int getMonth()[source]

Gets the current month.

Returns:

The current month.

public int getYear()[source]

Gets the current year.

Returns:

The current year.

public LocalDate toLocalDate()[source]

Converts this instance to a LocalDate.

Returns:

A LocalDate.

Since:

3.18.0

public LocalDateTime toLocalDateTime()[source]

Converts this instance to a LocalDateTime.

Returns:

A LocalDateTime.

Since:

3.17.0

public static LocalDateTime toLocalDateTime(Calendar calendar)[source]

Converts a Calendar to a LocalDateTime.

Parameters:

calendar – The Calendar to convert.

Returns:

A LocalDateTime.

Since:

3.17.0

public OffsetDateTime toOffsetDateTime()[source]

Converts this instance to a OffsetDateTime.

Returns:

A OffsetDateTime.

Since:

3.17.0

public static OffsetDateTime toOffsetDateTime(Calendar calendar)[source]

Converts a Calendar to an OffsetDateTime.

Parameters:

calendar – The Calendar to convert.

Returns:

A OffsetDateTime.

Since:

3.17.0

public ZonedDateTime toZonedDateTime()[source]

Converts this instance to a ZonedDateTime.

Returns:

A ZonedDateTime.

Since:

3.17.0

public static ZonedDateTime toZonedDateTime(Calendar calendar)[source]

Converts a Calendar to a ZonedDateTime.

Parameters:

calendar – The Calendar to convert.

Returns:

A ZonedDateTime.

Since:

3.17.0