Question

I am working on a microcontroller and don't want to keep track of time with the system clock. I want to make an HTTP request to get the current time in milliseconds from the epoch (1970). I already know how to form all the requests, I just can't find a url that can return this data to me. Who offers this as an API? I don't want to make an https request.

Was it helpful?

Solution

I have a site called Current Millis and theoretically infinite bandwidth. I think i can quickly write a php, say www.currentmillis.com/api/millis-since-epoch.php. Is this ok for you?

UPDATE: It was infinite bandwidth but not infinite resources.. Because the server can not hope to sustain millions of HTTP requests to a service that resolves time to the millisecond, that URL has been discontinued.. Instead minutes since epoch are offered now: http://currentmillis.com/time/minutes-since-unix-epoch.php (because within 1 minute the value can be cahced by the host server)

OTHER TIPS

https://now.httpbin.org/ is great for this - it returns a JSON array of the current time in different time formats, including time since epoch to a ridiculously small fraction of a second:

$ curl -s http://now.httpbin.org/
{"now": {"epoch": 1547752567.4569337, "slang_date": "today", "slang_time": "now", "iso8601": "2019-01-17T19:16:07.456934Z", "rfc2822": "Thu, 17 Jan 2019 19:16:07 GMT", "rfc3339": "2019-01-17T19:16:07.45Z"}, "urls": ["/", "/docs", "/when/:human-timestamp", "/parse/:machine-timestamp"]}

JSON should be easily parsable in any language, but if you're simply using a unix command-line then jq is a great utility for it:

$ curl -s http://now.httpbin.org/ | jq
{
  "now": {
    "epoch": 1547752558.6447814,
    "slang_date": "today",
    "slang_time": "now",
    "iso8601": "2019-01-17T19:15:58.644781Z",
    "rfc2822": "Thu, 17 Jan 2019 19:15:58 GMT",
    "rfc3339": "2019-01-17T19:15:58.64Z"
  },
  "urls": [
    "/",
    "/docs",
    "/when/:human-timestamp",
    "/parse/:machine-timestamp"
  ]
}

$ curl -s http://now.httpbin.org/ | jq '.now.epoch'
1547752585.5284808
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top