如何使用JavaScript获取原子钟?

时间:2019-07-15 11:31:39

标签: javascript

我想创建JavaScript倒计时,但是我必须使用原子钟(非本地PC时间)。 我找到了http://worldclockapi.com/api/json/est/now,它为您提供了JSON。

有一个属性 currentFileTime (时间戳),但没有UNIX时间戳。

如何将此时间戳转换为UNIX时间戳,获取日期对象并检查日期,小时,分钟和秒?

谢谢

1 个答案:

答案 0 :(得分:1)

只需选择一个时区并致电:

致电http://worldtimeapi.org/api/timezone/Europe/London.json

您将获得一个具有unix时间的json对象,如下所示:

let result = {"week_number":29,"utc_offset":"+01:00","utc_datetime":"2019-07-15T11:44:07.720355+00:00","unixtime":1563191047,"timezone":"Europe/London","raw_offset":0,"dst_until":"2019-10-27T01:00:00+00:00","dst_offset":3600,"dst_from":"2019-03-31T01:00:00+00:00","dst":true,"day_of_year":196,"day_of_week":1,"datetime":"2019-07-15T12:44:07.720355+01:00","client_ip":"194.153.217.248","abbreviation":"BST"}

// result["unixtime"] => 1563191047