如何获得给定城市的时间? [英] How to get the time of a given city?

查看:132
本文介绍了如何获得给定城市的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用JavaScript(并且没有Web服务或外部数据源)为特定位置显示时间,但是...
我想避免使用此解决方案,因为我不想必须考虑到夏令时,以及任何其他使其复杂的因素。

I know that I can display time for a particular location using only JavaScript (and no web service or external data source), but... I want to avoid using this solution because I don't want to have to account for daylight savings time, and any other factors that make it complicated.

我正在寻找一种更容易的方式来显示特定城市的时间和时间(或邮政编码,或任何标识符工作...)。

I'm looking for an easier way to display the time and always for a particular city (or zip code, or whatever identifier works...).

例如,我想要一个页面总是说:

For example, I want a page to always say:

迈阿密当前的时间是X

(其中X应该替换为迈阿密的当前时间)

(where "X" should be replaced by the current time in Miami)

是否有可以发布一些标识符(城市名称,邮政编码等)的Web服务(或任何其他方法),并返回时间? p>

Is there a web service (or any other method) where I can post some identifier (city name, zip code, etc) and get back the time?

推荐答案


是否有可以发布一些标识符(城市名称)的Web服务(或任何其他方法) ,邮政编码等),并回复时间?

Is there a web service (or any other method) where I can post some identifier (city name, zip code, etc) and get back the time?

我不知道一个可以完成这项工作的单一 Web服务。

I don't know of a single web service that will do the job.

Google的地理编码API 可以帮助您。您可以给它一个参数,它将返回一些信息,如纬度/经度。 使用邮政编码的示例,但我你确定你可以很容易地放在一个城市/国家对,并使之正常工作。

Google's Geocoding API can help. You can feed it a parameter, and it will return certain information, such as the latitude/longitude. Example using a zip code, but I'm sure you can easily put in a city/state pair and make it work.

然后你可以拿这个拉/长对,把它指向像 GeoNames 。他们有一个时区API ,采用拉/长对并返回相当多的信息。 使用邮政编码的lat / long示例

You can then take that lat/long pair and point it at service like GeoNames. They have a timezone API that takes a lat/long pair and returns quite a bit of information. Example using the lat/long from the zip code.

这篇关于如何获得给定城市的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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