kotlinx.datetime
Published Nov 14, 2023
Contribute to Docs
The kotlinx.datetime
library is designed to help Kotlin programmers with the most common issues dealing with date and time values. It emphasizes convenience so the API is as minimal as possible. The GitHub repository for the library has instructions on how to include a dependency in a Kotlin project.
The library uses the ISO 8601 standard and does not provide other ways to represent dates and times. It also doesn’t provide internationalization, so it can’t provide locale specific month and day names.
Below are various elements of the kotlinx.datetime
library:
kotlinx.datetime
- .asTimeZone()
- Convert a UtcOffset object to a time zone with a fixed offset.
- .atDate()
- Combines a date and time into a LocalDateTime object.
- .atStartOfDayIn()
- Finds an instant that corresponds to the start of a date in a particular time zone.
- .atTime()
- Combines a date and a time, resulting in a LocalDateTime object.
- .DateTimePeriod()
- Returns a DateTimePeriod object to indicate the time difference between two dates.
- .daysUntil()
- Returns the number of days between two Instants.
- .minus()
- Returns the difference between two dates or a date and a unit of time.
- .monthsUntil()
- Returns the number of months between two dates.
- .offsetAt()
- Finds the offset from UTC this time zone has at the specified instant of physical time.
- .offsetIn()
- Provides the time zone offset at a specific point in time.
- .periodUntil()
- Returns an object representing the difference between two dates.
- .plus()
- Adds a datetime object with a specified datetime period.
- .toDatePeriod()
- Parses the ISO-8601 duration representation as a DatePeriod.
- .toDateTimePeriod()
- Interprets an ISO-8601 formatted duration string, converting it into a DateTimePeriod object.
- .todayIn()
- Returns a date for the given Clock value and time zone passed.
- .toInstant()
- Converts a string representing an instant in ISO-8601 format, which includes both date and time components along with the time zone offset, into an Instant value.
- DayOfWeek
- Returns the name of the weekday based on the integer given, Monday is set as 1.
- Month()
- Returns an instance of a month object based on the integer given.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.