LocalDateUtil
LocalDateUtil provides utility methods for working with LocalDate objects. It includes methods for parsing, and extracting various date components.
Methods
parseDate(dateStr: String, format: String): LocalDate
Parses a date string using a custom format and returns a
LocalDateobject.Parameters:
dateStr(type: String) - The date string to parse.format(type: String) - The custom date format pattern used for parsing.
Returns:
A
LocalDateobject representing the parsed date.
var dateStr = "2023-11-07";
var format = "yyyy-MM-dd";
var parsedDate = LocalDateUtil.parseDate(dateStr, format);formatDate(date: LocalDate, format: String): LocalDate
Parses a date Formats a LocalDate object as a string using the specified format.
Parameters:
date(type: LocalDate) - The LocalDate object to be formatted.format(type: String) - The custom date format pattern used for formatting.
Returns:
A
Stringrepresenting the formatted date.
getYear(date: LocalDateTime): Integer
Retrieves the year component of a
LocalDateTimeobject.Parameters:
date(type: LocalDateTime) - TheLocalDateTimeobject from which to extract the year.
Returns:
An integer representing the year component.
getDayOfYear(date: LocalDate): Integer
Retrieves the day of the year component of a
LocalDateobject.Parameters:
date(type: LocalDate) - TheLocalDateobject from which to extract the day of the year.
Returns:
An integer representing the day of the year.
getMonthName(date: LocalDate): String
Retrieves the name of the month for a
LocalDateobject.Parameters:
date(type: LocalDate) - TheLocalDateobject from which to extract the month name.
Returns:
A string representing the name of the month.
getMonth(date: LocalDate): Integer
Retrieves the month component of a
LocalDateobject.Parameters:
date(type: LocalDate) - TheLocalDateobject from which to extract the month.
Returns:
An integer representing the month.
getDayOfWeek(date: LocalDate): String
Retrieves the day of the week for a
LocalDateobject.Parameters:
date(type: LocalDate) - TheLocalDateobject from which to extract the day of the week.
Returns:
A string representing the day of the week.
getDayOfMonth(date: LocalDate): Integer
Retrieves the day of the month component of a
LocalDateobject.Parameters:
date(type: LocalDate) - TheLocalDateobject from which to extract the day of the month.
Returns:
An integer representing the day of the month.
getWeekOfYear(date: LocalDate): Integer
Get the week number of the year for a given date.
Parameters:
date(type: LocalDate) - TheLocalDateobject to get the week number for..
Returns:
The week number of the year as an Integer.
getDateOfWeek(year: Integer, week: Integer, dayOfWeek: DayOfWeek): Integer
Returns the date of the week for the given year and week number.
Parameters:
year- The year for which to get the start date of the week.week- The week number for which to get the start date.dayOfWeek- The day of the week for which to get the date.
Returns:
The start date of the specified week in the specified year.
These methods provide various operations to work with LocalDate objects, including parsing date strings, and extracting individual date components.
Last updated
Was this helpful?