kotlinx-datetime: Multiplatform Date and Time Handling in Kotlin
\n\n1. What It Is and Why You Need It
\n\n kotlinx-datetime is an official library from JetBrains for working with date and time in the Kotlin ecosystem. Its main feature is multiplatform support: the same code works on JVM, JS (in browser and Node.js), Native (iOS, macOS, Windows, Linux), and Wasm. This saves developers from having to write platform-specific wrappers or use different libraries for different targets.\n
\n\n Why is it needed? The standard Kotlin/JVM library uses java.time, which is unavailable on other platforms. For Kotlin/Native and Kotlin/JS, developers had to either use platform-specific APIs (NSDate, Date) or include third-party libraries. kotlinx-datetime solves this problem by providing a unified API based on the ISO-8601 specification. It includes classes for representing moments in time (Instant), dates without time (LocalDate), time without date (LocalTime), date with time (LocalDateTime), time zones (TimeZone), and periods (DateTimePeriod).\n
\n The library is ideal for projects using Kotlin Multiplatform (KMP), server applications on Ktor, Android applications (as a replacement for java.time), and even for scripts and console utilities. It is lightweight, has no external dependencies, and is actively maintained by the community.\n
\n2. Installation
\n\n The library is distributed via Maven Central. To add it, you need to include the dependency in the build.gradle.kts (or build.gradle) file. The exact code for Gradle Kotlin DSL is provided below.\n
// build.gradle.kts\nrepositories {\n mavenCentral()\n}\n\ndependencies {\n // Main library\n implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.1")\n\n // If you are using a multiplatform project, add it to commonMain:\n // commonMain.dependencies {\n // implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.1")\n // }\n}\n\n \n Important: Version 0.6.1 is the latest stable version at the time of writing. Check the latest version on GitHub releases. For Gradle Groovy DSL, the command will be similar but without quotes around the strings.\n
\n\n If you are using Maven, add the following to pom.xml:\n
<dependency>\n <groupId>org.jetbrains.kotlinx</groupId>\n <artifactId>kotlinx-datetime</artifactId>\n <version>0.6.1</version>\n</dependency>\n\n \n For Gradle Kotlin DSL in a multiplatform project (KMP), add it to commonMain:\n
kotlin {\n sourceSets {\n commonMain.dependencies {\n implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.1")\n }\n }\n}\n\n 3. Quick Start
\n\n Minimal working example: getting the current moment in time, formatting it, and printing it to the console.\n
\nimport kotlinx.datetime.*\n\nfun main() {\n // Get the current moment in UTC\n val now: Instant = Clock.System.now()\n println("Current moment in UTC: $now")\n\n // Convert to local date and time (using the sys Also in library
Parsing HTML in C++: Libraries and Examples for Working with DOM and XPath
Machine Learning in Kotlin: Overview of KMath, Smile, KotlinDL, and DeepLearning4J Libraries
gRPC for Go (Golang): Libraries, Examples, and Practical Guide