在 Python 中获取计算机的 UTC 偏移量 [英] Getting computer's UTC offset in Python

查看:47
本文介绍了在 Python 中获取计算机的 UTC 偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Python 中,如何找到计算机设置的 UTC 时间偏移量?

In Python, how do you find what UTC time offset the computer is set to?

推荐答案

gmtime() 将返回 UTC 时间,localtime() 将返回本地时间,因此减去这两个应该给你UTC偏移量.

gmtime() will return the UTC time and localtime() will return the local time so subtracting the two should give you the utc offset.

来自 https://pubs.opengroup.org/onlinepubs/009695399/函数/gmtime.html

gmtime() 函数应将自计时器指向的纪元以来的时间(以秒为单位)转换为细分时间,以协调世界时 (UTC) 表示.

The gmtime() function shall convert the time in seconds since the Epoch pointed to by timer into a broken-down time, expressed as Coordinated Universal Time (UTC).

因此,尽管名称为 gmttime,但该函数返回 UTC.

So, despite the name gmttime, the function returns UTC.

这篇关于在 Python 中获取计算机的 UTC 偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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