我的代码中有一个函数,用于获取 UTC 时间参数,例如 -
2023-11-06T20:53:39.062Z
,将其转换为 EST 时间,然后以“MM-DD-YYYY HH:MM:SS”格式返回。
def date_conv(time):
est = zoneinfo.ZoneInfo('America/Toronto')
est_time = arrow.get(time).astimezone(est)
return str(arrow.get(est_time).format("MM-DD-YYYY HH:MM:SS"))
但是,这有时会返回时间为
16-11-2023 15:11:79
,其中秒字段 > 60,这是不可取的。代码到底有什么问题?
使用“MM-DD-YYYY HH:mm:ss”格式。
MM 代表月份(您使用它表示分钟),SS 代表亚秒,这就是为什么您得到的值大于 60。
查看完整文档以了解所有令牌: https://arrow.readthedocs.io/en/latest/guide.html#supported-tokens