
Facilitates network time synchronization by extending the `kotlinx-datetime` library with a `NetworkClock` class to retrieve and synchronize network time across Android, iOS, and desktop platforms.
Kotlin Multiplatform library for network time synchronization. It extends the kotlin.time 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.softartdev:kronos:$latestVersion")
}
}The main common interface is implemented using the following:
The project is built and tested using the following:
Kotlin Multiplatform library for network time synchronization. It extends the kotlin.time 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.softartdev:kronos:$latestVersion")
}
}The main common interface is implemented using the following:
The project is built and tested using the following: