Skip to content

How to use this library

Kaushik Gopal edited this page Sep 5, 2018 · 4 revisions


We use JitPack to host the library.

Add this to your application's build.gradle file:

repositories {
    maven {
        url ""

dependencies {
    // ...
    implementation 'com.github.instacart.truetime-android:library-extension-rx:<release-version>'

    // or if you want the vanilla version of Truetime:
    implementation 'com.github.instacart.truetime-android:library:<release-version>'


Vanilla version

Importing 'com.github.instacart.truetime-android:library:<release-version>' should be sufficient for this.

Then you must initialize it in onCreate() in your class that;

initialize also must be run on a background thread. If you run it on the main thread, you will get a NetworkOnMainThreadException

You can then use:

Date noReallyThisIsTheTrueDateAndTime =;

... #winning

Rx-ified Version

If you're down to using RxJava then we go all the way and implement the full NTP. Use the nifty initializeRx() api which takes in an NTP pool server host.

Again, you must initialize it in onCreate() in your class that
        .subscribe(date -> {
            Log.v(TAG, "TrueTime was initialized and we have a time: " + date);
        }, throwable -> {

Now, as before:; // return a Date object with the "true" time.
You can’t perform that action at this time.