How does utcnow() work without time-zones?

感情迁移 提交于 2019-12-13 04:37:55

问题


I am reading on SO that the Python standard library does not define any time-zones.

Also, from the Python 2.7 datetime docs:

Note that no concrete tzinfo classes are supplied by the datetime module.

However, calling utcnow() generates the current time in UTC. Furthermore, Python can also provide the current local time with now(). I am assuming that this is only possible if Python "knows" the local time-to-UTC offset (in order to return the correct values).

But doesn't that mean that Python is timezone aware? What am I missing?


回答1:


Your OS provides the current timezone, as well as UTC time.

The OS does not, however, provide other timezone info, such as when DST switches take place. In other words, you can get the current time in the UTC timezone, but not accurately calculate local time across the year, as the offset to UTC changes with the summertime and wintertime switches.



来源:https://stackoverflow.com/questions/18277191/how-does-utcnow-work-without-time-zones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!