使用python将UTC时间转换为经度和纬度的本地时间提供
我正在使用日出日落api来获取日间和日落。使用python将UTC时间转换为经度和纬度的本地时间提供
>>> 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时间转换为Long,Lat在URL中传递的当地时间。即不是用户本地。
任何帮助将不胜感激。
而不是使用网络查询你可能会更好使用pyephem,它是pip install pyephem
能够,并会给你日出/设置时间,(和更多),给定的位置,(拉特/长),基于物理值。
>>> import ephem
>>> sun = ephem.Sun()
>>> greenwich = ephem.Observer()
>>> greenwich.lat = '51:28:38'
>>> print(greenwich.horizon)
0:00:00.0
>>> greenwich.date = '2007/10/1'
>>> r1 = greenwich.next_rising(sun)
>>> greenwich.pressure = 0
>>> greenwich.horizon = '-0:34'
>>> greenwich.date = '2007/10/1'
>>> r2 = greenwich.next_rising(sun)
>>> print('Visual sunrise: %s' % r1)
Visual sunrise: 2007/10/1 05:59:30
>>> print('Naval Observatory sunrise: %s' % r2)
Naval Observatory sunrise: 2007/10/1 05:59:50
好吧,我会试试看,但我宁愿准确 –
我认为你会发现pyhehem如果使用正确的话,它的精确度非常高,当然它也可以离线工作。 –
它也在观察者位置的utc和时间之间转换。 –
的可能的复制[Python的 - 转换UTC时间字符串当地日期时间(https://stackoverflow.com/questions/4770297/python-convert-utc-datetime-string-to-local-datetime) – Rahul
@Rahul我不想转换为本地日期时间 –
使用pytz进行时区转换。 https://stackoverflow.com/questions/10997577/python-timezone-conversion – Rahul