Search code examples
web-servicesunix-timestamp

Unix timestamp web service


Is there somewhere over the Internet a reliable web service that returns current Unix (UTC) timestamp?


Solution

  • A plausible workaround could be to use response headers that we get with HTTP responses. In some rare cases like mine, when you haven't direct access to web server and you can't create an API by yourself, you could send an XHR and fetch the response headers with

    response.getAllResponseHeaders()

    and then parse the date value inside returned string. Of course you have to trust the server date. I know that is a rare (and maybe dumb) use case, but it could happen.