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 private java.util.Calendar
calendar
static CalendarUtils
INSTANCE
The singleton instance forCalendar.getInstance()
.private java.util.Locale
locale
-
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 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.(package private) static CalendarUtils
getInstance(java.util.Locale locale)
Gets a CalendarUtils using the default time zone and specified locale.int
getMonth()
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.int
getYear()
Gets the current year.
-
-
-
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()
-
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.FORMAT
locale.- 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. 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.
-
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.
-
-