npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

expo-true-time

v0.1.2

Published

My new module

Downloads

10

Readme

📦 expo-true-time — Reliable Time Synchronization for React Native (Expo)

expo-true-time is a library designed for reliable date-time management in React Native (Expo) projects,
capable of retrieving the real time from an NTP server and maintaining estimated UTC time without network connectivity.

It works on Android using SystemClock.elapsedRealtime and is only compatible with Android devices.


🚀 Features

  • ✅ Retrieves accurate UTC time from Google NTP servers (getNtpTime, getNtpTimeMS)
  • ✅ After one-time NTP synchronization, estimates time without internet
  • ✅ Returns UTC time in ISO format (getNtpTime, getEstimatedTimeUtc)
  • ✅ Provides UTC time as timestamp (getNtpTimeMS)
  • ✅ Retrieves device uptime since boot (getUpTime)
  • ✅ Compatible with Expo & bare React Native

📥 Installation

# Using npm
npm install expo-true-time

# Or using yarn
yarn add expo-true-time

📄 Usage

1️⃣ Get UTC Time from NTP (ISO String)

import { getNtpTime } from "expo-true-time";

const utcString = await getNtpTime();
console.log(utcString);
// "2025-08-04T10:35:10.583Z"

2️⃣ Get UTC Timestamp (ms) and Use setBaseUtcTime

import { getNtpTimeMS, setBaseUtcTime } from "expo-true-time";

const ntpTimestamp = await getNtpTimeMS(); // timestamp (ms)
await setBaseUtcTime(ntpTimestamp); // set as base UTC time

⚠️ Important: setBaseUtcTime should be provided a timestamp (ms), not an ISO string.


3️⃣ Get Estimated UTC Time

import { getEstimatedTimeUtc } from "expo-true-time";

const estimatedUtc = await getEstimatedTimeUtc();
console.log(estimatedUtc);
// "2025-08-04T10:35:10.583Z"

4️⃣ Get Device Uptime

import { getUpTime } from "expo-true-time";

const upTimeMs = await getUpTime();
console.log(upTimeMs);
// E.g., 3600000 (1 hour in milliseconds)

⚡ Includes time while the device was awake and asleep.
⚡ Not affected by system clock changes.
⚡ Returns a Long (ms) value.


⚙️ API Reference

| Method | Description | Parameter | Return Type | | ---------------------------- | ------------------------------------------------------------- | ------------ | ----------------------------------- | ----- | | getNtpTime() | Retrieves UTC time from Google NTP servers (ISO string) | None | string "YYYY-MM-DDTHH:mm:ss.sssZ" | | getNtpTimeMS() | Retrieves UTC time as timestamp (ms) from Google NTP servers | None | number (ms) | | setBaseUtcTime(ms: number) | Sets a base UTC timestamp for calculating estimated UTC time | ms: number | void | | getEstimatedTimeUtc() | Returns the estimated UTC time in ISO format | None | string | null | | getUpTime() | Returns the device uptime since boot (includes awake + sleep) | None | number (ms) |


📌 Notes

  • ⚠️ Android devices only.
  • Internet is required initially for NTP synchronization.
    • Alternatively, you can provide a trusted source's UTC timestamp (ms) to setBaseUtcTime.
    • Afterwards, getEstimatedTimeUtc() can provide estimated UTC time without network.
  • After getNtpTimeMS() is stored via setBaseUtcTime, estimated time works offline.
  • The library does not handle timezone conversions; it only returns UTC time.

📜 License

MIT © 2025 — Emre Dönmez & Contributors