通过HTTP从epoch获取毫秒

时间:2013-09-24 05:02:46

标签: api http timestamp epoch

我正在使用微控制器,不想跟踪系统时钟的时间。我想发一个HTTP请求来获取epoch(1970)的当前时间(以毫秒为单位)。我已经知道如何形成所有请求,我只是找不到可以将这些数据返回给我的网址。谁将此作为API提供?我不想发出https请求。

2 个答案:

答案 0 :(得分:7)

我有一个名为Current Millis的网站,理论上是无限带宽。我想我可以快速写一个php,比如www.currentmillis.com/api/millis-since-epoch.php。这对你好吗?

更新:它是无限的带宽,但不是无限的资源。因为服务器不能希望将数百万的HTTP请求维持到一个解析时间到毫秒的服务,所以该URL已经停止。而是提供了纪元以来的分钟现在:http://currentmillis.com/time/minutes-since-unix-epoch.php(因为主机服务器可以在1分钟内完成该值)

答案 1 :(得分:0)

https://now.httpbin.org/非常有用-它以不同的时间格式返回当前时间的JSON数组,包括从纪元以来的时间,可笑的很小的几分之一秒:

$ 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应该可以以任何语言轻松解析,但是如果您只是使用unix命令行,那么jq是一个很棒的实用程序:

$ 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