Python 根据本地时间获取 UTC 偏移量
在 so 上查了一下,可以用如下代码获取本地时间相对于 UTC 时间的偏移量,代码实现思路比较简单,分别获取本地时间和和 UTC 时间,然后本地时间减去 UTC 时间即可得到相对于 UTC 的偏移小时,代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/4/6 上午10:28
# @Author : qhh0205
# @Mail : qhh0205@gmail.com
# @File : utc_offset.py
import time
from datetime import datetime
ts = time.time()
utc_offset = int((datetime.fromtimestamp(ts) - datetime.utcfromtimestamp(ts)).total_seconds() /