Ultra-precise, framework-free time display for the web. NTP-synced, drift-free rendering via performance.now() ��� just one script tag. ~6 kB, zero dependencies, CDN-ready.
  • JavaScript 92.8%
  • Python 7.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-09-03 09:51:38 +02:00
.github/workflows Add GitLab and Forgejo repository sync 2026-09-03 09:51:38 +02:00
demo Update logo 2026-07-31 03:38:43 +02:00
dist v1.0.0 — initial release 2026-05-07 07:47:41 +02:00
img Update logo 2026-07-31 03:38:43 +02:00
src v1.0.0 — initial release 2026-05-07 07:47:41 +02:00
.gitignore v1.0.0 — initial release 2026-05-07 07:47:41 +02:00
CHANGELOG.md Migrate branding to neikiri.dev 2026-05-16 22:09:32 +02:00
CODE_OF_CONDUCT.md Migrate branding to neikiri.dev 2026-05-16 22:09:32 +02:00
CONTRIBUTING.md v1.0.0 — initial release 2026-05-07 07:47:41 +02:00
LICENSE v1.0.0 — initial release 2026-05-07 07:47:41 +02:00
minify.py v1.0.0 — initial release 2026-05-07 07:47:41 +02:00
README.md Improve README presentation 2026-07-31 03:54:46 +02:00
SECURITY.md Migrate branding to neikiri.dev 2026-05-16 22:09:32 +02:00

Neiki's Time

Neiki's Time

JavaScript
License Version

Ultra-Precise Time Display
NTP-synced, drift-free, framework-free — just one script tag.

Enjoying Neiki's Time? Give it a Star and Fork the repository! ❤️
Your support helps me see that the project is useful to developers
and motivates me to keep improving it with more frequent updates.

Fork the project



Live demo: https://neikiri.dev/time


Quick Start (CDN)

Add two lines to any HTML page — no build tools, no frameworks, no dependencies:

<div data-neiki-time></div>
<script src="https://cdn.neikiri.dev/neiki-time/neiki-time.min.js"></script>

That's it. The clock syncs automatically and starts ticking.

Unminified version also available at https://cdn.neikiri.dev/neiki-time/neiki-time.js


🔧 Configuration

NeikiTime.init({
  selector: '[data-neiki-time]',  // CSS selector for clock elements
  timezone: 'Europe/Prague',       // IANA timezone (undefined = local)
  locale: 'cs-CZ',                // Intl locale
  showDate: true,                  // show date part
  showMs: true,                    // show milliseconds
  showOffset: false,               // show sync debug info
  syncInterval: 60000,             // re-sync interval in ms
  syncSamples: 3,                  // samples per API per sync round
  theme: 'auto',                   // 'light' | 'dark' | 'auto' | 'none'
  onSync: function(info) {},       // callback after successful sync
  onTick: function(date) {}        // callback every animation frame
});

📌 Data Attributes

Per-element overrides via HTML attributes:

Attribute Description
data-neiki-time Marks element as a clock (required)
data-neiki-tz="Asia/Tokyo" Override timezone for this element
data-neiki-nodate Hide the date part
data-neiki-noms Hide milliseconds
data-neiki-offset Show sync offset & RTT debug info

📡 JavaScript API

Method Returns Description
NeikiTime.init(options?) Initialize and start rendering
NeikiTime.destroy() Stop everything, release resources
NeikiTime.sync() Promise Trigger manual re-sync
NeikiTime.now() number Precise UTC timestamp in ms
NeikiTime.date() Date Precise Date object
NeikiTime.isSynced() boolean Whether time has been synced
NeikiTime.getSyncInfo() object|null Last sync info (offset, rtt, api)

🧠 How It Works

  1. Parallel queries to multiple public time APIs (WorldTimeAPI, TimeAPI.io)
  2. Multiple samples per API — selects the one with the lowest round-trip time
  3. NTP-style offset: offset = serverTime (t0 + rtt/2)
  4. Anchors to performance.now() for monotonic, drift-free ticking
  5. requestAnimationFrame() for smooth ~60 fps rendering
  6. Periodic re-sync (default every 60 s) to correct any residual drift

Typical accuracy: ±1580 ms depending on network latency. Between syncs, performance.now() guarantees zero drift.


📄 License

This project is licensed under the MIT License — see the LICENSE file for details.


👨‍💻 Author

neikiri GitHub: https://github.com/neikiri


📬 Contact

📧 Email: neikiri@neikiri.dev