Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

server-date

> 编程语言
Open source

Make the server's clock available in the browser.

194 stars0 likes3 views
WebsiteGitHub

About

Make the server's clock available in the browser.

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

javascript
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

  • Cristian, Flaviu (1989), "Probabilistic clock synchronization", Distributed Computing (Springer) 3 (3): 146–158, DOI:10.1007/BF01784024
  • MikeWyatt's answer and Willem Mulder's comment in Sync JS time between multiple devices
  • Rob W's answer to How to synchronise a client webpage timer with the server

Copyright

Copyright 2012 David Braun

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptclockdatejavascriptserver

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言