首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pyephem本地时间问题

Pyephem本地时间问题
EN

Stack Overflow用户
提问于 2019-03-31 17:03:32
回答 1查看 108关注 0票数 1

我有一个在英国运行得很好的延时python脚本,现在我住在法国,它仍然在计算标准的GMT时间。我如何更改代码,使其代表我的实际位置?

代码语言:javascript
复制
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个小时,当然这是没有用的。

EN

回答 1

Stack Overflow用户

发布于 2019-04-01 10:26:57

如果没有内置世界时区边界映射,PyEphem无法将经度/经度转换为时区,遗憾的是,它没有。

但是您的计算机操作系统知道您的时区(如果您已经设置了时区),并且PyEphem有一个"localtime()“函数,它将向操作系统请求用于打印时间的时区:

https://rhodesmill.org/pyephem/date.html#time-zones

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55439331

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档