Kotlin Multiplatform library for network time synchronization. It extends the kotlin.time
API and supports the following platforms:
- Android
- iOS
- Desktop JVM (MacOS, Linux, Windows)
The library extends the main Clock
interface from the standard library. You can use the Clock.Network
class to retrieve the current network time, similar to using the built-in Clock.System
instance.
val networkTime: Instant = Clock.Network.now() // 2025-06-30T13:42:43.712Z
val systemTime: Instant = Clock.System.now() // 2025-06-30T13:42:43.566455Z
val diff: Duration = networkTime - systemTime // 145.545ms
When running the application, it's necessary to synchronize the time with the network using the platform-specific code:
- Android:
class App : Application() {
override fun onCreate() {
super.onCreate()
Clock.Network.sync(applicationContext)
}
}
- iOS:
@main
struct iosApp: App {
init() {
Clock.Network.sync()
}
var body: some Scene { ... }
}
- Desktop JVM:
fun main() {
Clock.Network.sync()
...
}
The latest release is available on Maven Central.
- Add the Maven Central repository if it is not already included:
repositories {
mavenCentral()
}
- In multiplatform projects, add the following dependency to the
commonMain
source set dependencies:
commonMain {
dependencies {
implementation("io.github.softartdev:kronos:$latestVersion")
}
}
The main common interface is implemented using the following:
- lyft/Kronos for Java & Android
- MobileNativeFoundation/Kronos for iOS
The project is built and tested using the following:
- Swift Klib Gradle Plugin for including Swift source files in KMM shared module
- Compose Multiplatform, by JetBrains for UI samples