Elastic Beanstalk未按预期运行strptime

问题描述 投票:0回答:1

我正在Elastic Beanstalk上运行python 3.6。当我尝试使用strptime时,出现以下错误:

ValueError: time data '2020-03-01 13:31:00 EST' does not match format '%Y-%m-%d %H:%M:%S %Z'

仅从该错误中,您可以看到时间数据确实与格式匹配。除了眼神之外,还有什么呢?我的代码如下:

r['SCHEDULE_TIME'] = 2020-04-01 13:31:00 EST
scheduleTime = datetime.strptime(r['SCHEDULE_TIME'],'%Y-%m-%d %H:%M:%S %Z')

EDIT:这与在python 3.7中执行python 3.6版本脚本有关。我需要在3.6中运行它,有没有办法做到这一点?

python datetime strptime
1个回答
0
投票

对于将来遇到这种情况的人,我的解决方案是将时区从时间戳中拉出,并在使用时间戳创建日期时间后直接使用replace(tzinfo = timezone_string_from_timestamp)设置日期时间的tzinfo属性。

© www.soinside.com 2019 - 2024. All rights reserved.