【发布时间】:2020-07-28 05:25:04
【问题描述】:
我正在尝试从 GMT 转换为例如 SGT:
例如值
0348 GMT 应该是上午 11:48 格林威治标准时间 1059 应该是下午 6:59
我该怎么做?
我试过了:
date="03:48"
curr = (
dt.datetime.strptime(date, "%H:%M")
.astimezone(timezone('Asia/Singapore'))
)
print(curr)
但我收到 OSError: [Errno 22] Invalid argument
【问题讨论】:
-
你有什么尝试吗?看看例如
dateutil获取时区?对于 SGT,您必须使用名称“亚洲/新加坡”。 -
@MrFuppesi 更新了它
-
我没有日期,只有那个表格中的时间
-
@AmeyaRane:
pytz是 to be deprecated,请改用dateutil,或者在 Python 3.9 中使用zoneinfo。