@nodeguy/server-date

5.1.0 • Public • Published

Changes

This version has been rewritten and breaks compatibility with the previous API.

Introduction

server-date makes the server's clock available to the client's web browser in JavaScript.

You can use it when you want to display the current time but don't trust the browser's clock to be accurate or to synchronize events for different users of your web site by syncing them all to the server's clock.

serverDate.js, gets the time from the server on which the library is hosted by reading the Date HTTP response header. You don't need to make any changes on the server if you use this version but its precision is limited to seconds because that's what's available in the header.

Usage

import { getServerDate } from "./serverDate.js";

const { date, offset, uncertainty } = await getServerDate();

console.log(`The server's date is ${date} +/- ${uncertainty} milliseconds.`);

// some time in the future

const serverDate = new Date(Date.now() + offset);

See example.html for a complete example.

References

Copyright

Copyright 2012 David Braun

Package Sidebar

Install

npm i @nodeguy/server-date

Weekly Downloads

25

Version

5.1.0

License

MPLv2

Unpacked Size

25.3 kB

Total Files

8

Last publish

Collaborators

  • nodeguy