Skip to content

Finally, a date you can trust! Function to easily get the time on an http server so you don't have to rely on whatever the local computer's time is.

Notifications You must be signed in to change notification settings

CharlesWall/get-origin-time.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

getOriginTime

Don't want to depend on unreliable client time? You're in luck. Every http request includes the servers time in UTC. This module makes a http request and inspects the Date response header then returns the time as a string.

Usage

const getOriginTime = require('get-origin-time');

async function doSomethingBasedOnAccurateTime() {
    const dateString = await getOriginTime({
        url, // url to request uses window.location.origin by default
        method, // http method to use, HEAD by default
        timeout // how long to wait for the server to respond 10s by default
    });
    const originTime = new Date(dateString);
    // ... do something interesting with the time
}

About

Finally, a date you can trust! Function to easily get the time on an http server so you don't have to rely on whatever the local computer's time is.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published