https://github.com/raheemadamboev/server-time-android
🕜 Light library to get real UNIX time from the server in android
https://github.com/raheemadamboev/server-time-android
android android-library get-time internet-time server-time
Last synced: 29 days ago
JSON representation
🕜 Light library to get real UNIX time from the server in android
- Host: GitHub
- URL: https://github.com/raheemadamboev/server-time-android
- Owner: raheemadamboev
- License: apache-2.0
- Created: 2021-10-06T18:42:36.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-08-03T09:48:06.000Z (10 months ago)
- Last Synced: 2025-08-03T11:29:49.277Z (10 months ago)
- Topics: android, android-library, get-time, internet-time, server-time
- Language: Kotlin
- Homepage:
- Size: 9.87 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-internettime - beat time library for Android
README
Server Time
🕜 ServerTimeAndroid is a light library to get real UNIX time from the Google server in Android. Sometimes phone's local date can be wrong so for the best accuracy it is better to get time from the server. It gets time from the Google server and always gets the correct date.
# Setup
Add the maven library bucket to the `dependencyResolutionManagement.repositories` block in `settings.gradle.kts` file as follows:
```kotlin
dependencyResolutionManagement {
...
repositories {
...
maven("https://jitpack.io")
}
}
```
Install the library to the project in desired module's `build.gradle.kts` file. Replace `` with the actual version:
```kotlin
implementation("com.github.raheemadamboev:server-time-android:")
```
# Implementation
**Get server time (callback API):**
```kotlin
ServerTime().execute { time ->
when (time) {
ServerTime.Result.UNKNOWN_HOST -> {
// handle internet not working or error in host
}
ServerTime.Result.IO_EXCEPTION -> {
// handle io exception
}
else -> {
// time (milli seconds) was retreived successfully
// println(Date(time).toString())
}
}
}
```
**Get server time (suspend API):**
```kotlin
viewModelScope.launch {
val time = ServerTime().execute()
when (time) {
ServerTime.Result.UNKNOWN_HOST -> {
// handle internet not working or error in host
}
ServerTime.Result.IO_EXCEPTION -> {
// handle io exception
}
else -> {
// time (milli seconds) was retreived successfully
// println(Date(time).toString())
}
}
}
```
# Demo

# Projects using this library
**GoTest** 250 000+ downloads in Google Play Store
**Buxgalteriya schyotlar rejasi** 50 000+ downloads in Google Play Store
**Irregular Verbs** 25 000+ downloads in Google Play Store
# License
```xml
Designed and developed by raheemadamboev (Raheem) 2022.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```