我有一个在英国运行得很好的延时python脚本,现在我住在法国,它仍然在计算标准的GMT时间。我如何更改代码,使其代表我的实际位置?
import sys
import os
import time
import ephem
#find time of sun rise and sunset
sun = ephem.Sun()
home = ephem.Observer()
home.lat, home.lon = '45.226691', '0.013133' #your lat long
sun.compute(home)
sunrise, sunset = (home.next_rising(sun),
home.next_setting(sun))
daylightminutes = (sunset - sunrise) * 1440 # find howmany minutes of daylight there are
daylightminutes = (round(daylightminutes))
sunriselessonemin = ephem.date(sunrise + 1*ephem.minute)
print "prog started at(home.date) = %s" %(home.date)
print "datetime = %s" % time.strftime("%Y/%-m/%-d %H:%M:%S")
print "sunrise = %s" %sunrise
print "sunset = %s" %sunset
print "daylight mins = %s" %(daylightminutes)
....
while ephem.now() <= sunrise:
time.sleep(1)
dostuff()代码假定现在是gmt时间的sunrize/sunset,而不是我的本地时间,尽管我知道我实际的经度/经度。所以目前在法国,我们比格林尼治标准时间提前了2个小时,当然这是没有用的。
发布于 2019-04-01 10:26:57
如果没有内置世界时区边界映射,PyEphem无法将经度/经度转换为时区,遗憾的是,它没有。
但是您的计算机操作系统知道您的时区(如果您已经设置了时区),并且PyEphem有一个"localtime()“函数,它将向操作系统请求用于打印时间的时区:
https://stackoverflow.com/questions/55439331
复制相似问题