- JavaScript 92.8%
- Python 7.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .github/workflows | ||
| demo | ||
| dist | ||
| img | ||
| src | ||
| .gitignore | ||
| CHANGELOG.md | ||
| CODE_OF_CONDUCT.md | ||
| CONTRIBUTING.md | ||
| LICENSE | ||
| minify.py | ||
| README.md | ||
| SECURITY.md | ||
Neiki's Time
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.
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
- Parallel queries to multiple public time APIs (WorldTimeAPI, TimeAPI.io)
- Multiple samples per API — selects the one with the lowest round-trip time
- NTP-style offset:
offset = serverTime − (t0 + rtt/2) - Anchors to
performance.now()for monotonic, drift-free ticking requestAnimationFrame()for smooth ~60 fps rendering- Periodic re-sync (default every 60 s) to correct any residual drift
Typical accuracy: ±15–80 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