【发布时间】:2017-07-31 05:54:13
【问题描述】:
我正在使用日出日落 api 来获取当天的日出和日落。
>>> url = "https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400&date=2017-07-31"
>>> import urllib2
>>> import json
>>> resp = urllib2.urlopen(url)
>>> data = json.load(resp)
>>> sunriseUtc = data.get("results").get("sunrise")
>>> sunriseUtc
u'5:23:18 AM'
我想将此 UTC 时间转换为在 URL 中传递的 Long、Lat 的本地时间。即不是本地用户。
任何帮助将不胜感激。
【问题讨论】:
-
@Rahul 我不想转换为本地日期时间
-
使用 pytz 进行时区转换。 stackoverflow.com/questions/10997577/python-timezone-conversion
-
您是指“当地时间”还是“天文时间”?因为和当地时间不一样,比如华沙的当地时间和巴黎的时间是一样的,尽管天文时间相差很大……
-
这不是那个的副本。难题是根据经度和纬度确定您所在的国家/地区,然后确定该国家/地区的 UTC 偏移量,然后在给定 UTC 偏移量的情况下以这些经纬度坐标生成本地时间。
标签: python datetime utc timezone-offset