没有时区的utcnow()如何工作? [英] How does utcnow() work without time-zones?

查看:123
本文介绍了没有时区的utcnow()如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关Python标准库未定义任何时区的信息。

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

此外,来自Python 2.7 datetime文档

Also, from the Python 2.7 datetime docs:


请注意,datetime模块未提供具体的tzinfo类。

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

但是,调用 utcnow()会生成UTC的当前时间。此外,Python还可以通过 now()提供当前本地时间。我假设只有在Python知道本地到UTC的时间偏移量(以便返回正确的值)的情况下才有可能。

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).

但是不这意味着Python 时区可以识别吗?我缺少什么?

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

推荐答案

您的操作系统提供了当前时区以及UTC时间。

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

操作系统不会,但是会提供其他时区信息,例如发生DST切换的时间。换句话说,您可以获取UTC时区中的当前时间,但是由于夏时制和冬令式切换到UTC的偏移量会发生变化,因此无法准确计算全年的本地时间。

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.

这篇关于没有时区的utcnow()如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆