
Network time synchronization library enhances the time API, providing a unified method to retrieve network time via an extended Clock interface, ensuring precise time management across platforms.
A fork of the original kronos library with the following changes:
Kotlin Multiplatform library for network time synchronization. It extends the kotlinx.datetime API and supports the following platforms:
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.545msWhen running the application, it's necessary to synchronize the time with the network using the platform-specific code:
class App : Application() {
override fun onCreate() {
super.onCreate()
Clock.Network.sync(applicationContext)
}
}@main
struct iosApp: App {
init() {
Clock.Network.sync()
}
var body: some Scene { ... }
}fun main() {
Clock.Network.sync()
...
}The latest release is available on Maven Central.
repositories {
mavenCentral()
}commonMain source set dependencies:commonMain {
dependencies {
implementation("io.github.sunragav:kronos:$latestVersion")
}
}dependencyResolutionManagement {
repositories {
maven { url = uri("https://jitpack.io") } // Required for
}
}The main common interface is implemented using the following:
The project is built and tested using the following:
A fork of the original kronos library with the following changes:
Kotlin Multiplatform library for network time synchronization. It extends the kotlinx.datetime API and supports the following platforms:
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.545msWhen running the application, it's necessary to synchronize the time with the network using the platform-specific code:
class App : Application() {
override fun onCreate() {
super.onCreate()
Clock.Network.sync(applicationContext)
}
}@main
struct iosApp: App {
init() {
Clock.Network.sync()
}
var body: some Scene { ... }
}fun main() {
Clock.Network.sync()
...
}The latest release is available on Maven Central.
repositories {
mavenCentral()
}commonMain source set dependencies:commonMain {
dependencies {
implementation("io.github.sunragav:kronos:$latestVersion")
}
}dependencyResolutionManagement {
repositories {
maven { url = uri("https://jitpack.io") } // Required for
}
}The main common interface is implemented using the following:
The project is built and tested using the following: