免费的 Rest API 以字符串形式检索当前日期时间(与时区无关) [英] Free Rest API to retrieve current datetime as string (timezone irrelevant)

查看:26
本文介绍了免费的 Rest API 以字符串形式检索当前日期时间(与时区无关)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种可靠的 REST API,它可以提供跨平台的世界时间和时区信息.

I am seeking a reliable REST API that can provide world time and time zone information across platforms.

我需要将当前时间作为字符串.我希望它能够在一秒内返回结果,而不管用户在全球的位置.

I need the current time as a string. I'd like it to return the result in under a second, regardless of the user's location worldwide.

在其他实现中,我想将它用于一致的倒数计时器,比用户的 [可能不准确] 计算机时间更准确.它可以是 GMT 或其他时区,只要指定时区和偏移量即可,例如 2012-11-05 16:16:50 EST.

Among other implementations I want to use this for a consistent countdown timer, to be more accurate than a user's [possibly-inaccurate] computer time. It can be GMT or another time zone, as long as the time zone and offset is specified, like 2012-11-05 16:16:50 EST.

我会自己构建这个 API,但是在通过像 Rails 这样的整个大型软件堆栈过滤某人以返回一个简单的 String 时,我担心潜在的延迟问题(以及不优雅).

I would build this API myself, but have concerns of potential latency issues (as well as inelegance) when filtering someone through a whole big software stack like Rails just to return a simple String.

远离美国东海岸的用户的过度延迟会抵消任务所需的准确性优势.

Excessive latency for users far away from the US east coast would offset the benefit of accuracy that the task requires.

感谢任何建议和/或示例.

Any suggestions and/or examples are appreciated.

推荐答案

如果你使用 Rails,你可以在 public 文件夹中创建一个空文件并使用 ajax 来获取它.然后解析日期标头的标头.Public 文件夹中的文件绕过 Rails 堆栈,因此延迟更低.

If you're using Rails, you can just make an empty file in the public folder and use ajax to get that. Then parse the headers for the Date header. Files in the Public folder bypass the Rails stack, and so have lower latency.

这篇关于免费的 Rest API 以字符串形式检索当前日期时间(与时区无关)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆