accutime
v1.3.1
Published
A JS library that fetches time from multiple sources and returns the time.
Downloads
27
Readme
accutime
Accurate time for the browser.
Use me
Browser
<script src="https://cdn.jsdelivr.net/npm/accutime@latest/dist/accutime.min.js"></script>
CommonJS
npm i accutime
const accutime = require('accutime');
ESM
npm i accutime
import accutime from 'accutime';
Usage
getTime
accutime.getTime();
Get the time.
Returns a promise that resolves to:
{
"datetime": "2024-02-01T11:33:36.841Z",
"timezone": "Europe/London",
"utc_offset": "+00:00",
"unix": 1706787216841
}
ntpJS
accutime.ntpJS(timezone: string)
Parameters:
- Timezone: (optional) A timezone. See full list here.
Get the time from https://use.ntpjs.org/v1/time.json.
Returns a promise that resolves to:
[
{
"now": 1706787368.862806,
"backoff": 375,
"__server": "lhrlhr"
},
62
]
The first value in the array is the response from the server.
The second value in the array is the amount of time it took to make the request.
worldTimeApi
accutime.worldTimeApi(append: string)
Parameters:
- append: (required) A appendix to the URL
https://worldtimeapi.org/api/
. In practise, you can append a timezone orip
for time at your IP. See the World Time API website for details.
Todo
- [x] Fix requests for the server.
- [ ] Add real NTP for server clients.