python - Timedelta returned by tzinfo object
问题描述
I'm studying datetimes in python and have come to timezones. I created a Pacific timezone
with a timedelta
pacific = datetime.timezone(datetime.timedelta(hours=8))
Then, I created an aware datetime
object which I converted to pacific with the tzinfo
object
aware = datetime.datetime(2020,12,20,11, tzinfo=pacific)
aware returns a timedelta
and I would like to know what it's calculating. It's -1, 57600
print(aware)
>>> datetime.datetime(2020,12,20,11,0, tzinfo=datetime.timezone(datetime.timedelta(-1,57600))
解决方案
这里发生的是有两种方法来表示时区偏移。
您可以用 28800 秒的时间增量(比 UTC 时间晚 8 小时)来表示它。或者等效地,您可以通过返回 1 天(-1)然后添加 57600 秒来表示它。这也为太平洋地区的 UTC 提供了 28800 秒(8 小时)的时间。
推荐阅读
- node.js - Azure 应用服务与节点进程管理器中断,但适用于节点
- css - 输入为带有 -webkit-appearance 的多行 TEXTAREA
- alibaba-cloud - 阿里巴巴 ECS 实例卡在“待启动”状态
- devexpress - 两个摘要结果的差异 null
- go - dynamodbattribute.UnmarshalMap 将我的变量类型转换为 map[string]interface{}
- android - 具有多个清单的 Android 项目
- cassandra - 我有单个集群 2 节点数据中心,在进行复制测试时,我关闭了 1 个节点,然后通过运行 nodetool status 命令出现错误
- sublimetext3 - 如何在 sublime text 3 中打开我们的本地程序(npptfp)?
- r - 自动化 ggplot2 的 qplot
- c# - 将 JSON 匹配到 C# 类,坐标结构